Java Socket exception

Source: Internet
Author: User

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
    1. java.net.connectexception: connection refused: connect   
    2.     at java.net.plainsocketimpl.socketconnect (Native Method)   
    3.     at java.net.plainsocketimpl.doconnect ( plainsocketimpl.java:351)   
    4.     at  Java.net.PlainSocketImpl.connectToAddress (plainsocketimpl.java:213)   
    5.      at java.net.plainsocketimpl.connect (plainsocketimpl.java:200)   
    6.     at java.net.sockssocketimpl.connect (sockssocketimpl.java:366)   
    7.     at java.net.socket.connect (socket.java:529)   
    8.     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

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.