Pushing live data on HTTP connections -> handling closed connection on client side #3199
-
Hello. Using http logger from your tutorial, the Q is - what is the way to understand that connection is closed at client`s side, when we simply close browser window? Is it possible to modify below function to handle disconnectein event? static void broadcast_message(struct mg_mgr *mgr, const char *message) { |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
When a connection is closed, either from your handler or from the other end, that handler will receive a CLOSE event, then the connection will be removed from the connection list. The piece of code you wrote (presumably part of the example code that could have been referred with a simple permalink, to avoid assumptions and etc), apparently parsing all connections, apparently looking for some tag put by the example, will put data in a buffer and that may or may not be sent depending on when the connection is closed. |
Beta Was this translation helpful? Give feedback.
-
There is no "old connection". There is no "aborted externally".
If a TCP connection is closed, your event handler will receive an MG_EV_CLOSE event. Whatever you need to happen when a connection is closed, you handle by catching that event. After that, that very connection will be removed from the Mongoose connection list.
|
Beta Was this translation helpful? Give feedback.
There is no "old connection". There is no "aborted externally".
HTTP runs over TCP
If a TCP connection is closed, your event handler will receive an MG_EV_CLOSE event. Whatever you need to happen when a connection is closed, you handle by catching that event. After that, that very connection will be removed from the Mongoose connection list.
If a TCP connection is not closed, it remains in the Mongoose connection list, as expected.
If you don't receive an MG_EV_CLOSE event, then the connection is not being clo…