Java Socket exception

Source: Internet
Author: User

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.




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.