Archived

This topic is now archived and is closed to further replies.

UDP server using only two ports?

This topic is 5844 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, Is it possible (and a good idea) to only use two ports for a server app which communicates with more than one client app? As I was thinking of only using one port for sending (to all client apps) and one for receving (from all client apps) and then using the ip address of the sender to figure out which client it came from or would it be better (faster) to use one port to receive from each client and only one to send to all the clients? Cheers, Daniel

Share this post


Link to post
Share on other sites
Do not confuse socket and port : you can have several (client) sockets connected to the same port. With TCP, the server socket spawns a new socket for each client. With UDP, all clients are connected to the same socket and, yes, you distinguish between them based on their IP. You don''t, however, need to have separate sockets for sending and receiving. You can use the same.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:
Original post by Fruny
Do not confuse socket and port : you can have several (client) sockets connected to the same port. With TCP, the server socket spawns a new socket for each client. With UDP, all clients are connected to the same socket and, yes, you distinguish between them based on their IP. You don''t, however, need to have separate sockets for sending and receiving. You can use the same.


Will there be any difference in the performance of the network code if I only use two sockets to comunicate with all the clients instead of using onw socket per client?

Covnict@Large

Share this post


Link to post
Share on other sites
The OS allocates an internal data structure for each socket used. It''s allocated in non-paged pool memory which you can run out of. With UDP, you generally don''t connect and just use sendto / recvfrom.

As for the two sockets, there''s not much reason to use 2 sockets instead of one.

Share this post


Link to post
Share on other sites