Below is information on how my company solves these problems:
1) if you can establish a connection without immediately receiving an error, you must assume that the connection is established. If you did not receive the answer immediately (badly or otherwise), you just need to assume that it works ... does some tough client-side households, so it is important to use sequence identifiers wisely.
2) Just try again right away. Typically, the server shuts down before the client executes and sends an error code informing you that this has happened. Just make sure you use something as reasonable as 20 seconds for your server side polling time.
3) You must switch to a different domain name than other requests to the same office computer and use jsonp. For example, if your page is hosted on example.com, the chat.example.com subdomain usually exists, since most browsers only allow 3 or 4 open connections at the same time with the same domain name. Jsonp is needed due to the same origin policy. In addition to this: test, test, test.
Ryan Dahl (creator of node.js) has a very simple client / chat server implemented here: https://github.com/ry/node_chat
Good luck
source share