UDP server using only two ports?

Started by
2 comments, last by ConvictAtLarge 22 years, 4 months ago
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
Advertisement
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.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
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

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.

This topic is closed to new replies.

Advertisement