websockets - how to know when session ends

54 views
Skip to first unread message

Ake Hedman

unread,
May 22, 2016, 7:07:00 AM5/22/16
to mongoose-users

I use moongose for a server on Linux and Windows and among other protocols I use websockets. This works well  for mots parts but I have one problem.

My users has to log in into the server and for that do a handshake process. When logged in some session data is  allocated. Eventually they log out from the connection the session data is deallocated and everything is OK.  BUT the problem is how to know when a connected dies for some other reason. That is, the page is closed or whatever.   How do I detect this so that I can deallocate session data?

/Ake

Sergey Lyubka

unread,
May 23, 2016, 5:24:51 AM5/23/16
to mongoose-users
MG_EV_CLOSE is sent to the closing connection - do you see this event in your websocket handler ?

--
You received this message because you are subscribed to the Google Groups "mongoose-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongoose-user...@googlegroups.com.
To post to this group, send email to mongoos...@googlegroups.com.
Visit this group at https://groups.google.com/group/mongoose-users.
For more options, visit https://groups.google.com/d/optout.

Ake Hedman

unread,
May 23, 2016, 5:32:54 AM5/23/16
to mongoose-users
Can I rally be sure that MG_EV_CLOSE happens for all client scenarios? I mean in the same sense as a standrad socket.

Sergey Lyubka

unread,
May 23, 2016, 5:47:10 AM5/23/16
to mongoose-users

Sorry Ake, I didn't get your question :-)

Ake Hedman

unread,
May 23, 2016, 6:03:52 AM5/23/16
to mongoose-users
Sorry for that Sergey,

I mean will  MG_EV_CLOSE be issued after a  web browser crash,  page close etc etc or are there scenarios when it will not be issued?  I open a session now when a socket is opened and close it when it is closed (command) or when  MG_EV_CLOSE is received.  Still it looks like I get some orphan sessions laying around some times.

Sergey Lyubka

unread,
May 23, 2016, 8:57:21 AM5/23/16
to mongoose-users
I anticipate MG_EV_CLOSE to be delievered on every instance when TCP connection is terminated.
If you can pinpoint the case when it's not like that, please report on how that can be reproduced.

--

Ake Hedman

unread,
May 23, 2016, 11:05:23 AM5/23/16
to mongoose-users
I have two cases when Mongoose give me problems. Both intermittent,  and hard to repeat.  This is one of them.  I see it from time to time.  The other is that websocket events stop being delivered all together after some points. No clue why.  Have seen this many times in all versions for at least a year. If I ever find a way to repeat I promise to report.   Thanks for now and thanks for very good and useful tools hard to live without.
Reply all
Reply to author
Forward
0 new messages