• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Get remote port for connection

 
venkatesh Nunna
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
whenever client sent the request to server, then the server accept the request and assign a new port number. How to get that port number on client side? please give answer that question friends
 
Rob Spoor
Sheriff
Pie
Posts: 20512
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch!

Socket has method getLocalSocketAddress() to return the socket address (host + port) for the local side (in your case the server) and getRemoteSocketAddress() to return the remote socket address for the other side (in your case the client). You'll need to cast the result to InetSocketAddress (after using instanceof to make sure it's safe) to be able to get the host and port.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic