four abnormal solutions

sponsored links how best to use it? This requires us to first understand the relevant issues related to the language. Hope that helps. Then we take a look at the of relevant knowledge.

The first one exception is Address already in use: JVM_Bind.

The exception occurred on the server for new ServerSocket (port) (port is an integer value 0,65536) operation. The reason is that with the exception of the port as a port has been started, and eavesdropping. At this point with the netstat-an command, you can see a Listending state port. Just looking for a port can not be occupied to solve this problem.

2nd exception is Connection refused: connect.

The exception occurs on the client for new Socket (ip, port) operation, because the exception occurs or the machine with ip address can not be found (ie from the current machine does not exist to specify the ip route), or the ip exists, but can not find the specified port for listening. The problem occurs, first check the client ip and port there is a mistake, and if correct click the server from the client to see if ping ping pass, pass if they can ping (service server-side to cut out the need to ping the other way), then look at the server side of the monitor whether the procedures specified port start, this would certainly solve the problem.

Article 3 exception is Socket is closed,

The exception on the client and the server can occur. Anomaly is due to one's own initiative to close the connection (called the Socket of the close approach) and then to read and write operations on the network connection.

4th exception is (Connection reset or Connect reset by peer: Socket write error).

The exception in both client and server side may occur, causing the exception for two reasons, first is that if one end of the Socket is closed (or take the initiative to shut down or quit because of abnormalities caused by the closure), the other side is still sending data , sent the first data packet triggered the exception (Connect reset by peer). Another is the end of the exit, but did not close the connection when out of the other side if the data is read from the connection throws the exception (Connection reset). Simply put, that is disconnected after the read and write operation caused.

Article 5 exception is Broken pipe.

The exception on the client and server are possible. 4 abnormalities in the first case (that is, throw SocketExcepton: Connect reset by peer: Socket write error later), if we continue to write data is thrown the exception. The first two anomalies solution is to first make sure the program exits to close all network connections, followed by testing each other's close connection to action, find each other close the connection, we also have to close the connection.

Write network programs require attention to issues

1 problem is to correctly distinguish the long and the short connection. The so-called long connection is maintained through the establishment of the permanent. Short connection is in the following scenarios in preparation for data -> connection -> send data -> close the connection. Many of the programmers to write web applications for many years, actually do not know what is a long connection, what is a short connection.

No. 2 problem is the maintenance of the long connection. The so-called maintenance consists of two areas, first, detection of active fault with each other (not only call the close method of Socket), followed by testing each other's downtime, and network abnormal exit barrier. This is a robust communications program must have. Testing each other's active disconnection is very simple with one initiative to break the other if the time during operation, then the return value is only -1, once detected each other off with, you should take the initiative to close the side of the connection (call to Socket the close method).

The detection of the other side of the downtime, and network abnormal exit barrier common method is to use "heart", that is, the two sides periodically send data to each other, but also from the other party to receive "heartbeat", if not received in successive cycles other heartbeat, you can judge each other or abnormal release or network downtime or unreasonable, at this time also need to take the initiative to close one's own connection, if the client can be re-initiated after a certain time delay connections. Although there is a Socket keep alive option to maintain the connection, if using this option, it normally takes two hours to find each other's downtime, and network abnormal exit barrier.

The first three issues to deal with efficiency. Whether client or server, if it is a long process to connect at least two threads, one for receiving data, one for sending heartbeat, do not need a special thread to write data, of course, also need a class of threads (commonly known as Worker thread ) used for message processing, that is only responsible for receiving the data reception thread, and then distributed to Worker for data processing. If it is a short connection, you do not need to send the heartbeat of the thread, if the server also need a special thread for listening for connection requests. These are the overall requirements of a communication process, specifically how to design your program, it depends on the level of your own design.
  • StumbleUpon
  • Digg
  • TwitThis
  • Mixx
  • Technorati
  • Facebook
  • NewsVine
  • Reddit
  • Google
  • LinkedIn
  • YahooMyWeb

Related Posts of four abnormal solutions

  • haproxy should not keep an accurate record of the client IP,

    Apache + HAProxy a server (A) Rails App two servers (B, C) version = 2.0.4 Medium production.log suddenly discovered some time ago only shows haproxy of IP. And should not show the real client ip However, in / etc / haproxy.cfg has been annotated Ini ...

  • Msxml2.XMLHTTP version problem

    Projects with an import feature prototype.js of Ajax functionality to update the prompt, the code is very simple, do not have the framework of the background on a jsp to output Text, future use of timers and to update the page Ajax.request encountere ...

  • IBM Ajax Tutorial Series

    Links: Part 10: Using JSON for data transmission In the asynchronous application to send and receive information, you can choose to plain text and XML as data format. Ajax grasp of this issue ...

  • jquery ajax example

    1. Check js file $. ajax (( type: "GET", url: "test.js", dataType: "script" )) data $. ajax (( type: "POST", url: "xxxx", data: "name = zhaoaiqing & age = 25", success: function ( ...

  • Unable to load bean: type: struts-derfault.xml abnormal

    Struts2 in the use of a lot of friends from time to time we encountered this anomaly, leading to its main reason is because the wrong package, we have to be xwork-2.1.1.jar and struts2-core-2.1.2.jar, replaced xwork-2.0. 4.jar and struts2-core-2.0.14.jar

  • Answer: After 2.2 upgrade mysql question-driven

    windows installed after the mysql gem error, error is approximately: ArgumentError (NULL pointer given): (eval): 3: in `each_hash ' (eval): 3: in `all_hashes' This is feeling under the windows of the question if the mysql gem version libmysql ...

  • lighttpd + fastcgi built a server how to preserve the status of server

    Requirements: server-side has much static files, there is much use of c + + to prepare the operational components necessary to carry out these functions on the external packaging Published Service, server-side state required to preserve the client (simila

  • NoClassDefFoundError: javax / servlet / Servlet

    In the project in order to achieve a listener in web.xml set up a listener, did start in Tomcat actually occurred after java.lang.NoClassDefFoundError: javax / servlet / ServletContextListener this anomaly google and found the reasons for the lack of serv

  • Nan-Jing 5: When IBatis.Hibernate mixed affairs, pay attention to your SQL

    [Problem] Now, in the development of the so-called multi-storey JavaEE applications, data persistence layer is always essential, and "Automatic" of ORM - Hibernate, and "all-manual-type" of SqlMap - IBatis, equivalent data are Per ...

blog comments powered by Disqus
Recent Entries
Tag Cloud
Random Entries