0

I need to have a UDP server which allow me to receive/send informations from/to clients which dynamically will open a socket with a free port (so it will be differente from device and device). The client will send and receive in the same port, so the server must be able to communicate with it.

how could I set the server to stay open in every port? if I had 250 thousand users how could I handle them without tails problem and preventing the port to be occupied from another client?

I thought about open every port with different sockets in a different thread, but I don't know if this is a correct way.

user4789408
  • 1,196
  • 3
  • 14
  • 31

1 Answers1

0

A UDP Server can listen and be open on only one port. All clients can send data to that port. The server will have to handle each data and respond if needed to the peer who sent its data. This should happen even if more than one client wish to send data to server. In UDP context one client will not hog the server port.(Unless the application is badly written).

Prabhu
  • 3,443
  • 15
  • 26
  • So with UDP I will never have the port occupied ? With 10 client or 500 000 is it the same? I think that using only 1 port could be dangerous, in particular if I have to take care about DDOS, I will have only 1 port to do everything. In addition if every client send to the same port how the server could responds to the random port generated from the client for receiving? – user4789408 Apr 22 '15 at 17:33
  • How many clients can server handle is upto the design of how the application is. The point is UDP protocol does not say only one client can connect to a open port. If DDOS can happen in port it can as well be created in many ports that you open. Server knows the peer IP address and Port from the data that it receives. – Prabhu Apr 22 '15 at 17:41
  • If my client has already occupied the port I choosed to receive in my server, could the client send data to this port? – user4789408 Apr 22 '15 at 18:24
  • Clients do not 'occupy' port. They don't get tied up to that port. No established connection as in TCP. They send data destined to a server port. It can reach or be lost. Do try with simple server and clients. Have one instance of server running on a port. Many instances of client program running to send/recv data from server. – Prabhu Apr 22 '15 at 18:26
  • I mean maybe it cause problem because my application need to send in a port which is occupied in another application to receive. – user4789408 Apr 22 '15 at 19:52