Port number

This is a little doubt and something that really shouldn't come to mind. So please forgive me for this

To transfer messages between two hosts on a LAN, do the port numbers for sending and receiving data need to be the same?

+1


a source to share


4 answers


No. You will send to a known port number, but your client side port number will be essentially random. This means that multiple clients can send to the same server using different client-side port numbers, but only one known server number.

eg. if you have multiple clients on the same machine talking to a remote web server it would look like this:



localhost:31000 -> webserver:80
localhost:31001 -> webserver:80
localhost:31002 -> webserver:80

      

and you will only need to specify the webserver: 80 command. The client side numbers are ephemeral (see here for more information)

+2


a source


No.

It works like this



  • The client machine wants to talk to the server machine to know the port on the server machine, for example port 80 for http
  • The client machine opens a connection to the server machine. this is open on a random port on the client, but to a known port number on the server
  • The server sends back along this pipe until the port number the client reports it, a random one he opened
+1


a source


No, they don't. You need a known port to establish a connection on the host, but the client will create a socket with a random port number that is returned by the OS.

0


a source


Just to add my $ 0.02, the server can have multiple connections on the same socket. So if you have 3 clients all connecting to port 80, they can all be connected at the same time; you don't have to worry about one client clogging up the port.

0


a source







All Articles