Java Socket ExceptionCategory: Java 2013-07-15 22:38 981 people read comments (0) favorite reports
Directory (?) [+]
When you write a program using a Java socket, you typically encounter several exceptions: Bindexception, Unknownhostexception, Connectexception, Sockettimeoutexception.
bindexception
Occurs in the bind () operation of the socket or ServerSocket, this exception is thrown if it cannot be bound to the IP address or port specified by the native computer.
There are two types of situations:
- The specified IP address is not on the host
can be installed on a host of n network cards, can have multiple IP addresses, at the time of binding need to specify which IP address to bind to, 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, in two cases:
- The server is not listening on the specified port
- The backlog queue specified by the server socket is full
the exception information in two cases is the same:
[Plain]View Plaincopy
- 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)
Sockettimeoutexception
The Connect method can specify a time-out and throws this exception if there is no successful connection between timeout
Java Socket exception