• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

why is localport different?

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic