简体   繁体   English

C#-网络与服务器

[英]C# - Network vs. Server

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: CloseInventory和SendTab方法:

    /// <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. Serialize()方法基本上将标头和有效负载连接在一起。 The SendData() method just sends a byte array via the socket (asynchronously). SendData()方法仅通过套接字(异步)发送字节数组。

As you can see, im sending multiple packets basically at the same time, but in different arrays. 如您所见,im基本上同时在多个数组中同时发送多个数据包。 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? 分别发送和合并发送会有所不同吗?

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. 虽然还有其他问题...我认为针对数据部分选择udp vs tcpip更为重要。

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. 确实,问题在于数据包的频率与数据包的大小,到达/冗余的几率等(如果是udp)相对于要发送的数据总大小的优化问题。

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. 确实,您必须执行实验。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM