previous | start | next

Other Socket Operations

Java provides a few other entertaining socket operations, apart from reading from (via getInputStream(), and writing to (via getOutputStream()), the connected socket:
getInetAddress()
 
Returns the IP address of the system that this socket is connected to.
 
getPort()
 
Returns the port number that the socket is connected to on the remote system -- basically you'd hope that this is the same as you specified at "socket creation" time...:-)
 
getLocalPort()
 
Returns the port number on the local system. For a client socket, this will be the random (?) port number allocated when the initial TCP connection was established. Usually this isn't of much interest.

 
Lecture 9: Socket Programming Interface Copyright © 2005 P.Scott, La Trobe University Bendigo.


previous | start | next