two - what is the problem with assigning a port number to more than one server application

Multiple UDP Sockets to listen for specific source on the same port (2)

Since it is possible to construct a tcp socket and a udp socket that listens on the same port, is it possible to construct multiple sockets that listen for udp messages on the same port, with each listening for different source endpoints?

Design-wise, I'm currently under the impression that the 'correct' way to do it is just to have a single socket listening for all udp messages and have it determine the origin at the application level.

FYI I do not know PHP and I primarily use Linux, so your mileage may vary. It seems though that I might help you with some tcp knowledge. If you already know this, forgive me and ignore my answer ;)

So I don't know how you connected to your server socket and how your server handled the connection, but if it is programmed correctly your server will not occupy the port, hence blocking future connections. You can of course do that if you want to.

Normally when you create a server, you want to have 1 known port, so that multiple clients can connect to it (like port 80 for http). The server uses 'listen' to listen for connections, followed by an 'accept' and finally a 'close'. The accept makes sure that you can get multiple connections via your server port.


  • you can find a free port by opening a socket on port 0.
  • you can handle multiple sockets via 'select'
  • a nice book to read up on sockets is Working with Tcp sockets by Jesse Storimer (FYI I don't have stocks, only the book ;). But there are many intros to socket programming if your google fu is with you.

It is possible to have multiple UDP sockets listening on the same local IP/Port pair by using the SO_REUSEADDR socket option, but there is no way to tell each socket to only accept packets for its intended remote IP/Port pair, so there is no guarantee which socket will receive which packet. So yes, the correct option is to use a single socket that looks at the sending IP/Port of each received packet and directs the packet accordingly.