Hello everybody.
Why does the Socket class have a bind() method and how/what it
is used for - after all, Socket class implements only client's
socket, so it doesn't accept connections (and therefore doesn't
have an accept() method, like ServerSocket) and connection to a
server is establshed by calling connect(), so what does bind()
do?
Rob Skedgell - 16 Feb 2006 00:08 GMT
> Hello everybody.
>
[quoted text clipped - 4 lines]
> server is establshed by calling connect(), so what does bind()
> do?
You can create an unconnected Socket using the default constructor, then
use Socket.bind(SocketAddress) to use a specific (local) InetAddress
and port to connect *from*. You might want to use some of Socket's
setXXX methods to set other things before you connect it to the
endpoint using Socket.connect(SocketAddress).

Signature
Rob Skedgell <rob+news@nephelococcygia.demon.co.uk>
GnuPG/PGP: 7DA3 1579 C0DD 8748 C05A B984 E2A2 3234 D14B 6DD7