This is a small doubt and something that shouldn't really come to one's mind.So please forgive me for this
In order to transmit messages between two host on lan, do the port numbers to send and receive data have to be the same?
This is a small doubt and something that shouldn't really come to one's mind.So please forgive me for this
In order to transmit messages between two host on lan, do the port numbers to send and receive data have to be the same?
No, they don't. You need a well known port to establish the connection on the host, but the client will create a socket with a random port number returned by the OS.
No.
It works as follows
No. You will send to a known port number, but your client-side port number will essentially be random. This means that multiple clients can send to one server, using different client-side port numbers, but only the one known server-side number.
e.g. if you have multiple clients on one machine talking to a remote webserver, it would look like:
localhost:31000 -> webserver:80
localhost:31001 -> webserver:80
localhost:31002 -> webserver:80
and you'd only have to specify the webserver:80 combination. The client side numbers are ephemeral (see here for more info)
Just to add my $0.02, the server can have multiple connections open 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 "hogging" the port.