Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

why is localport different?  RSS feed

 
jeff willis
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After successfully connecting to a server here, I printed out the socket information and got the following:

Socket[addr=REPTESTPOST1/192.168.0.133,port=27253,localport=4707]


My question is: If I connected to port 27253 on the server, shouldn't I also have port 27253 on the client?

Also, if I were to connect again, the localport would increment to 4708.
 
Rovas Kram
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's rare when you get the same port on client and server. The server has to have a fixed port so that the client software can connect to it; for example port 80 on a webserver or port 25 for a ftp server. When the client opens a socket to the server, it will be assigned an available port from the operating system. This client port is where the response is sent from the server - say the html from a web server.
[ August 06, 2004: Message edited by: Rovas Kram ]
 
Afroz Ahmed
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's true.
The real genic happened in the inetraction between cl-server is this

The client Sends a request to an application running on some fixed port(say 80 for http req ) at server(an ip address).

The server gets the request and it sends the request to a random port(say port number 1000) on server for further interactions.

Now the server's port 80 is free and waiting for another requests.The random port is doing all the interactions with the client and it is the means by which the server knows and interacts with the client.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!