Forums Register Login

Get remote port for connection

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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.
I do some of my very best work in water. Like this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 3782 times.
Similar Threads
difference between Ports ?
java.net Socket port number question
Question about ServerSocket port number and Socket port number
Question on server Ports
why is localport different?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 02:47:46.