Java Network Programming Mastering (19): socket (Socket) exception

2011-08-03  来源:本站原创  分类:Internet  人气:77 

In the Socket class has many methods used in the statement throws throws some exceptions that are subclasses of IOException. In the method of the Socket class is thrown up SocketException, there are seven exceptions for the rest of the Socket class methods throw. The inheritance of these anomalies shown in Figure 1. Gray background box which exception is described in the methods of the Socket class may throw exceptions.

Java Network Programming Mastering (19): socket (Socket) exception

Figure 1 exception class inheritance diagram

  • public class IOException extends Exception

The exception is that all the methods of the Socket class in the parent class throws exception. Therefore, when using the Socket class as long as the catch (catch) the exception for; course, in order to capture both the methods of other classes in abnormal, can also catch Exception.

  • public class SocketException extends IOException

This unusual method of the Socket class to use most often. It also represents all the exceptions and networks. But if it is to know what kind of specific exception occurs, you need to capture more specific abnormal.

  • public class ConnectException extends SocketException

ConnectException exception usually occurs because the server is busy or the server without the appropriate response to the listening port is not open. Such as the following statement will throw an exception ConnectException.

Socket socket = new Socket ("www.ptpress.com.cn", 1234);

  • public class BindException extends SocketException

This anomaly in a number of Socket or ServerSocket object bound to the same port, but is not open when the SO_REUSEADDR option. As in the following four statements will throw an exception BindException:

Socket socket1 = new Socket ();
Socket socket2 = new Socket ();
socket1.bind (new InetSocketAddress ("127.0.0.1", 1234));
socket2.bind (new InetSocketAddress ("127.0.0.1", 1234));

  • public class NoRouteToHostException extends SocketException

The exception in the event of a firewall or router can not find the host of circumstances.

  • public class UnknownHostException extends IOException

This exception does not correct the domain name was thrown out. Such as the following statement will throw an exception UnKnownHostException:

Socket socket1 = new Socket ("www.ptpress123.com.cn", 80);

  • public class ProtocolException extends IOException

This exception does not often throw. Due to unknown reasons, TCP / IP packet is destroyed, then an exception will be thrown ProtocolException.

  • public class SocketTimeoutException extends InterruptedIOException

If the connection timeout and read timeout after the server is still not responding, connect or read methods will throw SocketTimeoutException exception.

相关文章
  • Java Network Programming Mastering (19): socket (Socket) exception 2011-08-03

    In the Socket class has many methods used in the statement throws throws some exceptions that are subclasses of IOException. In the method of the Socket class is thrown up SocketException, there are seven exceptions for the rest of the Socket class m

  • Java Network Programming Mastering (22): Implementing HTTP simulator 2011-08-03

    In discussing the specific HTTP protocol request and response header fields, let us first use of previously learned knowledge to implement an HTTP simulator. The so-called HTTP simulator is that you can enter the user's HTTP request message from the

  • Java Network Programming Mastering (31): non-blocking I / O Introduction 2011-08-03

    In network applications, in general, you can use synchronous I / O (block I / O) and non-blocking I / O data communication in two ways. These two methods are not mutually exclusive and replace each other. We can usually use a separate application in

  • Java Network Programming Mastering (33): non-blocking I / O buffer (Buffer) 2011-08-03

    If the synchronous I / O mode data transmission compared the data transmission of sporadic way (here is sporadic in the process of data transmission is sporadic in the way of bytes), then it can be non-blocking I / O mode of data transmission compare

  • Java Network Programming "shorthand" 2009-04-06

    1. What is the TCP / IP protocols? 2. TCP / IP transport protocol which of two kinds, each What are the characteristics? 3. What is the URL? 4. URL and the IP address of what kind of relationship? 5. What is a socket (Socket)? 6. Socket (Socket), and

  • Socket-based low-level Java Network Programming 2011-07-13

    1, what is the socket? The so-called socket often called the "socket" used to describe the IP address and port, a communication chain handle. Applications often want the network to send the request through the socket, or should the network reque

  • Java network programming sperm solution (01) 2010-08-29

    1 OSI Reference Model 1.1 ISO International Organization for Standardization (International Organization for Standization) 1.2 OSI open systems interconnection architecture (Open System Interconnection) 1.3 OSI network layer: Physical layer> data lin

  • java network programming instructions 2011-01-02

    java network programming refers to the network transport layer is based on Socket programming. Network communication is the essence of the two independent host (a computer in the network does not depend on another computer.) Ip address refers to a ho

  • JAVA Network Programming Socket FAQ [long special topic] 2010-03-18

    1. Network program is running in the common exceptions and handling The first one exception is java.net.BindException: Address already in use: JVM_Bind. The exception occurred on the server for new ServerSocket (port) (port is an integer value of 0,6

  • Java Network Programming - Building Secure Socket with SSL 2010-10-13

    SSL (Secure Sockets Layer) is the Netscape Corporation developed in 1994, initially for the WEB browser, the browser and the server data transfer between the provision of security, providing encryption, source authentication and data integrity featur

  • Analysis of problems in JAVA Network Programming () 2009-01-18

    Said network programming refers to Socket programming, the first listing what language to use JAVA programs Socket common abnormalities, causes and solutions, and then repeat that write network program about issues needing attention. In the analysis,

  • Basic input output IO Java Network Programming Review Minutes 2011-01-09

    IO / O → File Class The only information on behalf of the class itself, the disk file (not file content) File How → RandomAccessFile class Provides a large number of file access methods Support for "random access" methods (such as achieving brea

  • Reprinted java network programming note points 2010-03-18

    1. Network program is running in the common exceptions and handling The first one exception is java.net.BindException: Address already in use: JVM_Bind. The exception occurred on the server for new ServerSocket (port) (port is an integer value of 0,6

  • Java Network Programming Review 2009-11-01

    URL Use url = new URL("http://www.google.cn"); HttpURLConnection httpUrl = (HttpURLConnection) url .openConnection();// To open the URL gets HTTP Specific features of URLConnection BufferedReader br = new BufferedReader(new InputStreamReader( ht

  • java network programming to learn --- SOCKET 2010-03-22

    Today, learn how to simply use SOCKTE programming. Wanted to see how to use socket and communicate with each other sleepwalk of the serversocket made some mistakes, Mainly for socket streams of inputstream and outputstream the use of error. 1.writer

  • Java network programming non-blocking I / O 2010-07-16

    For the CPU faster than the network situation, the traditional solution is to buffer and Java multithreading. Multiple threads can simultaneously connect to several different generation data, and data stored in the buffer in which to know the network

  • Java Network Programming (11): get network interface to use the letter NetworkInterface class 2010-09-20

    Starting from JDK1.4, Java provides a NetworkInterface class. This class can get the machine all of the physical network interfaces and virtual machine software such as use of the machine's physical network interface to create a logical network inter

  • java network programming under the domain name for ip address, URL 2010-08-19

    Domain Name, the domain can be converted to ip address InetAddress can also use the getAddress () to get the IP address, but its return value is a 4 byte array. Thus, although getAddress () in the IP aspects of access is useful but not suitable for e

  • Java Network Programming 2010-03-29

    http://xangqun.javaeye.com/blog/487328

  • Java Network Programming fine solution - Sun Weiqin 2010-10-29

    Length 5.