tags:

views:

69

answers:

1

Hello,

I have been working on an emulator, and it sends a few packets separately, but the client receiving the packets is able to handle multiple packets incoming from a single receive.

Here's my method:

    /// <summary>
    /// Sends a few packets at login to prepare the character for gameplay.
    /// </summary>
    /// <param name="character">The character to produce frame for.</param>
    public void SendLoginWelcome(Character character)
    {
        character.Session.SendData(new NewMapRegionPacketComposer(character).Serialize());
        WelcomeScreen.Show(character);
        SendCloseInventoryInterface(character);
        SendTab(character, 6, 745);
        SendTab(character, 7, 754);
        SendTab(character, 11, 751); // Chat options
        SendTab(character, 68, 752); // Chatbox
        SendTab(character, 64, 748); // HP bar
        SendTab(character, 65, 749); // Prayer bar
        SendTab(character, 66, 750); // Energy bar
        SendTab(character, 67, 747);
        character.Session.SendData(new ConfigPacketComposer(character, 1160, -1).Serialize());
        SendTab(character, 8, 137); // Playername on chat
        SendTab(character, 73, 92); // Attack tab
        SendTab(character, 74, 320); // Skill tab
        SendTab(character, 75, 274); //  Quest tab
        SendTab(character, 76, 149); // Inventory tab
        SendTab(character, 77, 387); // Equipment tab
        SendTab(character, 78, 271); // Prayer tab
        SendTab(character, 79, 192); // Magic tab
        SendTab(character, 81, 550); // Friend tab
        SendTab(character, 82, 551); // Ignore tab
        SendTab(character, 83, 589); // Clan tab
        SendTab(character, 84, 261); // Setting tab
        SendTab(character, 85, 464); // Emote tab
        SendTab(character, 86, 187); // Music tab
        SendTab(character, 87, 182); // Logout tab
    }

CloseInventory & SendTab methods:

    /// <summary>
    /// Closes the inventory interface.
    /// </summary>
    /// <param name="character">The character to produce frame for.</param>
    public void SendCloseInventoryInterface(Character character)
    {
        character.Session.SendData(new InterfaceConfigPacketComposer(character, 
            (short)(character.Hd ? 746 : 548), 71, true).Serialize());
    }

    /// <summary>
    /// Sends a tab interface.
    /// </summary>
    /// <param name="character">The character to produce frame for.</param>
    /// <param name="tabId">The id of the tab.</param>
    /// <param name="childId">The child if of the tab.</param>
    public void SendTab(Character character, short tabId, short childId)
    {
        character.Session.SendData(new InterfacePacketComposer(character, 1,
            (short)(childId == 137 ? 752 : (character.Hd ? 746 : 548)), 
            tabId, childId).Serialize());
    }

The Serialize() method basically joins the header and the payload togeather. The SendData() method just sends a byte array via the socket (asynchronously).

As you can see, im sending multiple packets basically at the same time, but in different arrays. My question is what would be more efficient for the server's stability and performance, sending that method within an array (i have to join each of those arrays into one, then send via network) or send it raw after it's been composed.

Joining arrays may cause some performance issues, since this is a multi-player server, the more players the server has, the more the server load is. Would sending it separately vs. sending it merged make a difference? Please ask if you need any more of my code.

Thanks in advanced, AJ Ravindiran.

+1  A: 

The more packets you send the more bandwidth gets absorbed by their overhead.

There are other issues though ... i think the choice of udp vs tcpip for sections of data is more important.

Really you want to be compressing the data as bandwidth and latency is the bottleneck ... the costs of decompressing probably will be far less.

As for the performance question its impossible to answer a priori from what is given.

Really the problem is a optomisation problem of frequency of packets vs size of packets vs odds of arriving/reduncancy etc (if udp) against the size of the total size of data to send.

Its not much of an answer im afraid, but any authoritative answer really would be irresponsible.

Really you are goign to have to perform the experiement.

John Nicholas