atmosphere long-polling doesn't reconnect after connection loss - internet-explorer-8

After server crash or intermittent network failure, Atmosphere web socket client is able to reconnect to the server and receive messages. However, atmosphere long-polling client(IE8) fails to reconnect.
My app is a live event browser that subscribes to a topic and displays all application events. Chrome and Firefox are working great, but, unfortunately, we still need to support IE8, therefore consistent behavior between WebSocket and Long-Polling is crucial. What am I missing here? Is this an Atmosphere bug??
HOW TO REPRODUCE
download atmosphere-chat example v2.0.3
http://search.maven.org/#artifactdetails%7Corg.atmosphere.samples%7Catmosphere-chat%7C2.0.0%7Cwar
modify application.js to use long-polling and to reconnect forever with 5 seconds interval.
transport: 'long-polling'
reconnect: true,
maxReconnectOnClose: Number.MAX_VALUE
start Tomcat server and start chat
stop Tomcat abruptly
start Tomcat
Open another browser and send some message.
Original browser wouldn't receive message.
[Long Polling: Not-Working]
onOpen called with {"url":"http://localhost:8080/atmosphere-chat/chat","contentType":"application/json","logLevel":"debug","transport":"long-polling","trackMessageLength":true,"reconnect":true,"maxReconnectOnClose":1.7976931348623157e+308,"reconnectInterval":5000,"enableXDR":true,"fallbackTransport":"long-polling"} atmosphere.js:2801
onMessage called. {"message":"Chrome","author":"Chrome","time":1381083093440} atmosphere.js:2801
onMessage called. {"message":"Hello","author":"Chrome","time":1381083099605} atmosphere.js:2801
<< Server Crashed>>
POST http://localhost:8080/atmosphere-chat/chat?X-Atmosphere-tracking-id=0cbdf60…sport=polling&X-Cache-Date=0&Content-Type=application/json&_=1381083105434 atmosphere.js:1750
_executeRequest atmosphere.js:1750
_pushAjaxMessage atmosphere.js:2197
_push atmosphere.js:2143
push atmosphere.js:2511
request.onClose application.js:111
_f atmosphere.js:2405
_invokeFunction atmosphere.js:2361
_invokeCallback atmosphere.js:2455
_invokeClose atmosphere.js:2417
_executeRequest.ajaxRequest.onabort atmosphere.js:1593
_clearState atmosphere.js:344
_executeRequest.ajaxRequest.onreadystatechange atmosphere.js:1652
Unable to connect to http://localhost:8080/atmosphere-chat/chat atmosphere.js:2801
GET http://localhost:8080/atmosphere-chat/chat?X-Atmosphere-tracking-id=0cbdf60…-Date=0&Content-Type=application/json&X-atmo-protocol=true&_=1381083099613 atmosphere.js:1750
_executeRequest atmosphere.js:1750
_reconnect atmosphere.js:1840
_executeRequest.ajaxRequest.onreadystatechange atmosphere.js:1735
<< Never Retries>>
[Web Socket: Working ]
Invoking executeWebSocket atmosphere.js:2801
Using URL: ws://localhost:8080/atmosphere-chat/chat?X-Atmosphere-tracking-id=0&X-Atmosphere-Framework=2.0.3-javascript&X-Atmosphere-Transport=websocket&X-Atmosphere-TrackMessageSize=true&X-Cache-Date=0&Content-Type=application/json&X-atmo-protocol=true atmosphere.js:2801
Websocket successfully opened atmosphere.js:2801
onOpen called with with {"url":"http://localhost:8080/atmosphere-chat/chat","contentType":"application/json","logLevel":"debug","transport":"websocket","trackMessageLength":true,"reconnect":true,"maxReconnectOnClose":1.7976931348623157e+308,"reconnectInterval":5000,"enableXDR":true,"fallbackTransport":"long-polling"} atmosphere.js:2801
onMessage called. {"message":"Chrome","author":"Chrome","time":1381082675245} atmosphere.js:2801
onMessage called. {"message":"hello","author":"Chrome","time":1381082685115} atmosphere.js:2801
<< server crashed>>
WebSocket is already in CLOSING or CLOSED state. atmosphere.js:2296
Invoking executeWebSocket atmosphere.js:2801
Using URL: ws://localhost:8080/atmosphere-chat/chat?X-Atmosphere-tracking-id=3764cd2f-6338-4478-bf35-b9f5fa105c7e&X-Atmosphere-Framework=2.0.3-javascript&X-Atmosphere-Transport=websocket&X-Atmosphere-TrackMessageSize=true&X-Cache-Date=1381082719622&Content-Type=application/json&X-atmo-protocol=true atmosphere.js:2801
Invoking executeWebSocket atmosphere.js:2801
Using URL: ws://localhost:8080/atmosphere-chat/chat?X-Atmosphere-tracking-id=3764cd2f-6338-4478-bf35-b9f5fa105c7e&X-Atmosphere-Framework=2.0.3-javascript&X-Atmosphere-Transport=websocket&X-Atmosphere-TrackMessageSize=true&X-Cache-Date=1381082726651&Content-Type=application/json&X-atmo-protocol=true atmosphere.js:2801
Invoking executeWebSocket atmosphere.js:2801
Using URL: ws://localhost:8080/atmosphere-chat/chat?X-Atmosphere-tracking-id=3764cd2f-6338-4478-bf35-b9f5fa105c7e&X-Atmosphere-Framework=2.0.3-javascript&X-Atmosphere-Transport=websocket&X-Atmosphere-TrackMessageSize=true&X-Cache-Date=1381082733654&Content-Type=application/json&X-atmo-protocol=true atmosphere.js:2801
Invoking executeWebSocket atmosphere.js:2801
Using URL: ws://localhost:8080/atmosphere-chat/chat?X-Atmosphere-tracking-id=3764cd2f-6338-4478-bf35-b9f5fa105c7e&X-Atmosphere-Framework=2.0.3-javascript&X-Atmosphere-Transport=websocket&X-Atmosphere-TrackMessageSize=true&X-Cache-Date=1381082740657&Content-Type=application/json&X-atmo-protocol=true atmosphere.js:2801
<< server Restarted>>
Websocket successfully opened atmosphere.js:2801
onMessage called. {"message":"IE10","author":"IE10","time":1381082755699}
Thanks!

Related

org.eclipse.jetty.io.EofException of Jetty websocket

I utilize Jetty (9.4.1) websocket for 2 ways communication between client and server.
On Client side, the messages 'onerror' and 'onclose' of WebSocket are listened, so that when there is a problem, the client will make a
new connection.
On Server side, the 'OnError' and 'OnClose' messages also handled.
Then, sometimes I see server got an 'org.eclipse.jetty.io.EofException', 'OnError' and 'OnClose' of ServerEndpoint are invoked. But on the Client side, there is no 'onerror' or 'onclose' message is sent.
Therefore, in this case the Client is not aware of the websocket connection is closed already, still use that connection.
My questions are:
1. How can this EofException happen?
2. When this error happen, is the connection actually close or still open? Because I cannot duplicate this error programmatically, I cannot investigate to understand clearly.
3. How can I make Client aware of this exception, so that Client can reconnect and function properly?

websocket exception : ReceiveAsync and SendAsync can be called simultaneously

I have a websocket client in UI side and WebSocket server in C#.
I have a senario where client sending data to server and many data is coming from server to client at same time.After getting some data in UI socket is closing in UI side.
Getting the exception in server code:
The WebSocket is in an invalid state ('Aborted') for this operation. Valid states are: 'Open, CloseSent'.
But at the time of sending data from server to client i am checking the below condition :
if (socket.State == WebSocketState.Open)
{
await socket.SendAsync(new ArraySegment<byte>(buffer), WebSocketMessageType.Text, true, this.cts.Token);
}
getting another exception which i think is the main reason:
There is already one outstanding 'SendAsync' call for this WebSocket instance. ReceiveAsync and SendAsync can be called simultaneously, but at most one outstanding operation for each of them is allowed at the same time.
so due to the exception, client is disconnecting from server.Is there any solution for this problem?I am not getting any perfect solution.

Indy FTP Client OnStatus not getting Disconnect events

I have setup an Indy IdFTP Client to a FileZilla FTP Server.The client tries to Connect on startup of my app and, If it fails, keeps retrying every few seconds for the lifetime of the app. In addition, I need to detect if I lose the connection and, again, keep trying to re-establish the connection. This is where I am having a problem.
I have added an OnStatus event handler which seems to fire for all the event types except hsDisconnecting and hsDisconnected.
I also have an OnDisconnected event handler which only fires when I have locked the Server, in this case, when I try to connect, it fires the OnConnected then immediately fires the OnDisconnected. However, if I set the Server as not Active after the initial successful connection, the server tells me it has disconnected me but I do not get an event in my code so I don't know I need to start trying to connect again? Am I wrong in expecting these events in this scenario, is there something else I should be listening for?
Thank you in advance for your help.

How reconnect from server to client

I'am able to detect when client disconnect from a server by this code:
self._session.socket.on("close", function() {
console.log("client disconnected");
}
But how can I try reconnect to the disconnected client?
You cannot connect from server to client as client isn't listening to the websocket, but just connecting (to the server).
However, you can put a code in your client to reconnect it at onclose (or just close) event. Generally this occurs by recreating the WebSocket object in the client with the correct parameters.
Something as:
function connect(){
var mywebsocket = new WebSocket("ws://(your url)");
// ... my callbacks and functions...
mywebsocket.onclose = connect; // or arguments.callee
}
connect();
Should work correctly. ;)
Good luck.
If the client got disconnected for some reason (internet connection disruption/server issues) it will automatically reconnect on its own. To see how many attempts have been made or the status have a look at http://docs.meteor.com/#meteor_status
Since version 0.6.3 if the internet was disconnected. As soon as the internet is back it will attempt to reconnect too.
To reconnect from your code somewhere you can run Meteor.reconnect() from the client.
Unfortunately the meteor client can't listen for connections from the server so the server can't initiate a reconnection, you need some kind of connection to a server to send a message to the client to do something such as a reconnection.

How do i know if connection is alive with websockets?

I have a webapp, which is running in a browser. That webapp is connected to a server, which uses websockets. So the communication between the server and my client/browser is based on websockets. If some magic event occurs on the server, some webservice sends a new XML / JSON to my webapp and the new data gets displayed.
But how do i, as the client / browser, know if the connection is stil alive? Lets say i do not get any new XML for about 30 seconds. How would i know if the connection is closed/broken/server offline or everything is fine, but on the server himself no new magic event occured.
A websocket connection object has a readyState field which will tell you if the connection is still active (from the dart documentation). The readyState can be either
0 - connection not yet established
1 - conncetion established
2 - in closing handshake
3 - connection closed or could not open
You can also define an event handler for the websocket close event if this is something you'd like to handle (try to reconnect, etc).
3 ways:
rely on TCP to detect loss of connectivity, which will ultimately pop up in JS onclose event
send WebSocket pings from server .. browsers will reply with WS pongs, loss of connectivity is probably more robustly detected also on client side
send app level heartbeats from browser to server, server need to have logic to reply. you can't trigger WS pings from browsers (in JS)

Resources