Вопрос

I am at the beginning of writing an simple mmo server for demo game. I am using UDP protocol (UdpClient) but I wonder, how other servers are working?:

  1. only 1 UDP client that process all connected clients and messages and responds to them
  2. server creates a new UDP client instance for each connected player?

I have tested connecting 50 clients who send "Ping" message and server has to reply with "Pong". It takes about 10 seconds (on localhost) for the 50th "Pong" to send (in the mean time, server is supposed to send ping to 1st player as well so queue can be prolonged to hours which is absurd)

Это было полезно?

Решение

Other servers use 1) i.e. listen from any client with one Socket (of which I assume there is one per UdpClient) . Furthermore:

  • This one Socket should be used for the lifetime of the server, i.e. don't create a new one when done with one datagram.
  • Receives and sends should be done asynchronously so receiving/sending one stream doesn't hold up receiving/sending another stream.
  • Beware of the amount of data you send/receive - if you send/receive data to several clients from the server the total amount of data is multiplied by the amount of clients.

Doing the above on localhost with 50 clients sending ping and receiving a pong that is only a few bytes should take less than 1ms, assuming some other process is not maxing out the processors.

Другие советы

I'm going to qualify my answer by saying I don't know the internal structures of MMO servers. I'm a bit surprised that 50 ping/pongs requires 10 seconds, I would think, especially on localhost that it would be much faster. I suspect you have some sort of problem or perhaps your clients are particularly complex to initialize. I suggest you download something like Wireshark (http://www.wireshark.org/) and look at your IP traffic to see what is actually going on.

If you play a MMO you may also be able to use wireshark to look at the packets being transfer and get a better idea of what their servers are doing.

You must be doing something wrong. I wrote a server that handles 4 million ping/pong messages per second with 10-20 milliseconds delivery time on each message. I am using the TCP protocol.

I recommend that you read Beej's guide to socket programming, rewrite your client/server networking code and see if you get better numbers: http://beej.us/guide/bgnet/

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top