When writing programs with Java sockets, you typically encounter several exceptions: Bindexception, Unknownhostexception, Connectexception, Sockettimeoutexception. bindexception
Occurs in the bind () operation of the socket or serversocket, and this exception is thrown if the IP address or port specified by this computer cannot be bound.
There are two kinds of situations:
The specified IP address is not a host on the host can install N network card, can have more than one IP address, when binding to specify which IP address to bind, if the specified IP address is not on the current host, will throw an exception. The specified port is already occupied
unknownhostexception
When connect, this exception is thrown if the specified host name or IP address is not recognized. connectexception
Occurs in connect, there are two situations:
The server does not have the same exception information for the specified port server socket that the backlog queue is full of two conditions:
Java.net.ConnectException:Connection Refused:connect at
java.net.PlainSocketImpl.socketConnect (Native method) At
Java.net.PlainSocketImpl.doConnect (plainsocketimpl.java:351)
at Java.net.PlainSocketImpl.connectToAddress (plainsocketimpl.java:213) at
Java.net.PlainSocketImpl.connect ( plainsocketimpl.java:200) at
java.net.SocksSocketImpl.connect (sockssocketimpl.java:366)
at Java.net.Socket.connect (socket.java:529) at
java.net.Socket.connect (socket.java:478)
The Sockettimeoutexception Connect method can specify a time-out period, which is thrown if no connection between timeout is successful.