• Post Reply Bookmark Topic Watch Topic
  • New Topic

ServerSocket port and the Socket port  RSS feed

 
Ransika deSilva
Ranch Hand
Posts: 524
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I just wanted to know whether the serversocket port and the socket port of a client should match or not.
Thank you very much...
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Imagine that you've got several telephone numbers: a home number, a cell number, an office number. If someone calls you on the phone, they have to use the number that corresponds to the phone you're actually sitting near. If they call your home while you're at the office, they're not going to get ahold of you.

Same with TCP/IP port numbers. The ServerSocket has to listen on the same port that the Socket tries to contact, just like your friend has to call the same number as the phone you're near. So the answer is yes, they have to match.
 
Yaroslav Chinskiy
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In order to make unique address on the server, you use port number. So the address you r connecting to is ip ort (127.0.0.1:4565 for example). The address and the port of the caller does not matter. (unless you have some fire wall rules where you must set specific port for the caller)
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yaroslav is right, but he's talking about details that I don't believe Ransika was asking about. I think Ransika was just asking if the port numbers you pass to the ServerSocket constuctor and the basic Socket constructor need to match, and that's the question I was answering with a long and elaborate "Yes."
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!