On Nov 30, 2012, at 8:51 AM, Peter Kutrumbos <
peter.k...@gmail.com> wrote:
> I realize this may be an issue with my underlying web-socket code used in the DDP client, however using that same client I do get the appropriate onError and onClose messages during other scenarios such as when I redeploy the meteor server or if my DDP client loses internet connection.
>
> Has anyone had a similar experience or ideas on how to fix it or test this behavior better?
In general you can't rely on connection termination events/notification from the tcp/ip layer. Timeouts and other network setting beyond your control may prevent you from ever receiving a socket termination notice when communicating over the Internet. Only in tightly controlled environments (like using a loopback connection locally) will you get reliable socket close events.
If you need to properly detect and tear down socket connections you must do so at the application layer. Obviously this is a good idea to do in general as zombie connections will become memory leaks that will eventually take down your server. The easies technique is to add a "heartbeat" to your protocol - in meteor just create a meteor method that you can call every so often. - if your client doesn't receive a response after so many seconds assume the connection is no longer open and clean it up and do whatever connection recovery you can.
I would assume ddp itself contains a heartbeat in the underlying protocol for the same reasons so hopefully you can support the ddp heartbeat in your java library instead of creating your own. I don't know there is a built in ddp heartbeat for sure though so you'll have to research.
A heartbeat has the added bonus that you detect not only the socket being connected but also that the server is still responsive. If the server is hung up, blocked, resource starved, etc you would want your client to also detect that and respond appropriately.
-iain