D
D
DenisVladimirovich2017-07-16 23:57:14
C++ / C#
DenisVladimirovich, 2017-07-16 23:57:14

How to sort clients on UDP protocol?

Good evening (afternoon). I am writing a server in C. And when designing interaction, the question arose of sorting packages between clients. Tell me which is better?
1) There is a map of clients. When a packet is sent, I determine by IP:PORT whether there is such a client. Then, if not, then I create such a client in the stream and detail. And already inside it processes all incoming packets and executes only those that are sent to it. And so it is with every client.
2) There is again a list of clients, but in this case, each time a handler is called for the package without creating it in a thread.
3) Or option 2, only each package is a new thread for execution
What do you suggest? How to do it in udp? There was just one more idea: to open both TCP and UDP in one server. With a new TCP, create a client with a TCP connection and a UDP socket handle. And already inside to process.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
X
xmoonlight, 2017-07-17
@DenisVladimirovich

The choice depends on the type of game.
Usually, it is done separately:
1. Processing for unicast connections (sending to several clients at once). We create one endless stream. Upon receipt, we also process in one single thread.
2. Processor for client-server exchange (data that does not affect the gameplay of other players). We create "dying" stream instances. Processing in separate threads.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question