Flex client disconecting - apache-flex

I am using BlazeDS. Does anybody know how to disconnect client from server? Client must be informed about this event.
Thanks for help.

As far as I knew BlazeDS does not support open connections between the Flash Player and the server. You'll have to use LiveCycle if you want to do that.
When you make a server call using the HTTPService, WebService, or RemoteObject tags, there are events that fire when you receive feedback from the server, such as result or fault. When those events fire, you can safely assume that that service call is no longer connected ot the server.

Related

Stop server-sent events by server

When using server-sent events, how does server communicate to browser that there won't be more events and that it should close the sse connection?
Is this a part of the protocol or should this be implemented by passing hint in normal event to the client that it can close event source ?
The server-sent events is yet another streaming technique which is one of ways of Comet. To stop streaming data, just close the connection in server. You don't need to let client call close method of EventSource instance.
FYI, the following links show that how Cettia streaming transport backed by server-sent events implements to close connection. (Note that I'm an author of Cettia)
Java server - https://github.com/cettia/cettia-java-server/blob/1.0.0-Beta1/server%2Fsrc%2Fmain%2Fjava%2Fio%2Fcettia%2Ftransport%2Fhttp%2FHttpTransportServer.java#L358
JavaScript client - https://github.com/cettia/cettia-javascript-client/blob/1.0.0-Beta1/cettia.js#L884-L886
Edit
For that issue, I added es.close within es.onerror.

blazeds,how to know the client has "disconnected"?

The blazeds server-side don't know the client-side has disconnected. But it seems to know the client-side's network has down.
In my case, I use the polling channel, I download the blazeds's source code, and add some log output in the FlexClientOutboundQueueProcessor.flush(MessageClient messageClient, List<Message> outboundQueue) method.
Then I saw this, when a client subscibed, the server-side invoke the FlexClientOutboundQueueProcessor.flush method every 3 seconds, and print what I added in the flush method, then I only shut down the client's network, not close browser(client and server with difference network), I found the server-side don't print anything, it means that the server-side don't invoke the flush method.
And after more than 30 minutes I recover the client's network, the server-side continue to invoke the flush method (the client's session isn't destroyed, if I close the client's browser, after 30 minutes the server-side will destroy the session).
Now, I have two questions,:
How the server-side know the client's network has downed? Is there a listener to monitor the client's network? If so, where is it? If not, how and where the codes?
It seems that the server-side will invoke the FlexClientOutboundQueueProcessor.flush method every 3 seconds, can this interval be configured? And where the code to start or stop this timing task?
Here answer on your first question: Detecting (on the server side) when a Flex client disconnects from BlazeDS destination
About configuration. You can configure in services-config.xml.
Example BlazeDS applications
Configuring channels with servlet-based endpoints

Is polling the way to go for live chat on web?

I'm trying to implement a custom live chat program on the web, but I'm not sure how to handle the real-time (or near real-time) updates for users. Would it make more sense to send Ajax requests from the client side every second or so, polling the database for new comments?
Is there a way to somehow broadcast from the database each time a comment is added? If this is possible how would that work? I'm using Sql Server 2008 with Asp.net (c#).
Thanks!
Use long polling/server side push/comet:
http://en.wikipedia.org/wiki/Comet_(programming))
Also see:
http://en.wikipedia.org/wiki/Push_technology
I think when you use long polling you'll also want your web server to provide some support in the form of non-blocking io for requests, so that you aren't holding a thread per connection.
You could have each client poll the server, and at the server side keep the connection open without responding.
As soon there is a message detected at server side, this data is returned through the already open connection. On receipt, your client immediately issues a new request.
There's some complexity as you need to keep track server side which connections is associated with which session, and which should be responded upon to prevent timeouts.
I never actually did this but this should be the most resource efficient way.
Nope. use queuing systems like RabiitMq or ActiveMQ. Check mongoDB too.
A queuing system will give u a publish - subscribe facilities.

Detect FlexClient disconnect on Longpolling Channel

I'm developing a chat system and i need to detect the FlexClient disconnect in Java, using the longpolling channel.
I can't use the Streaming channel, because of some bugs that this kind of channel still has. Do you have any suggestion on how could i accomplish this? I'm using BlazeDS.
Regards.
There is no way to detect a client disconnect in real time unless using an RMTP channel which is using behind a socket. When using different channels you can do some workarounds like having some javascript in your web detecting the page unload event, or you can have your client using some kind of heart bit mechanism.

Possible for webservice to send message from server to client?

I'm pretty sure this isn't possible with HTTP 1.1 or webservices, but just want to double check with you guys (and thus will probably be switching this application to WCF).
I want to send a message from the server an asp.net webservice is running on, to the client consuming it. Is this possible without polling (IE an interrupt based model)?
In WCF, you do have a thing called duplex bindings, which allows the server to call back into the client at a specific address.
See the MSDN documentation on duplex channels for a first impression of what those are.
I don't think you can do this with ASMX.
Marc

Resources