Is there any source where i can find implementation of timeout on websocket close function?

47 views
Skip to first unread message

Mert Öztürk

unread,
Feb 9, 2015, 6:37:00 AM2/9/15
to chica...@googlegroups.com
Hello,

I am having a little bit of trouble with the websocket close function. When the client closes (exits) my app on browser, my websocket handle close function doesnt work properly and i can not delete the user from my mock boss_db database.This is a big problem for me because that client is still seen as online and system tries to send messages to that client although client doesnt exist.

I found this from older posts but i think the link is broken.


Is there any example of websocket with a timeout added?

Thanks
Mert

chan sisowath

unread,
Feb 9, 2015, 7:32:45 AM2/9/15
to chica...@googlegroups.com
hi Mert,

can you check if handle_close work for a given version of CB ?

--
You received this message because you are subscribed to the Google Groups "ChicagoBoss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chicagoboss...@googlegroups.com.
Visit this group at http://groups.google.com/group/chicagoboss.
To view this discussion on the web visit https://groups.google.com/d/msgid/chicagoboss/62ea4065-ac34-43f8-807b-e1bbf9797d46%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Mert Öztürk

unread,
Feb 9, 2015, 7:42:34 AM2/9/15
to chica...@googlegroups.com
Hello Chan,

I am using latest Chicagoboss version 0.8.13 and your websocket example for your app draw.

95% handle_close is working fine but sometimes it doesnt catch browser exits. 
In my app i have two databases. One of them is mock which i use it for online users and the other one is MongoDB which is for returning clients.
When a client opens the app in browser, client is saved on boss_db mock with my parameters.
When client closes browser window, handle close function deletes the user from boss_db mock. So i can use the boss_db mock to give service to online clients without any registeration.

So the problem is handle close sometimes doesnt work and client can not be deleted from boss_db mock. That client still looks online and try to retrieve messages although client doesnt exist anymore.
So i decided to implement timeout to the user which doesnt have any activity within 5 minutes and get deleted from boss_db mock.

Is it possible?

Thanks
Mert

9 Şubat 2015 Pazartesi 14:32:45 UTC+2 tarihinde mihawk yazdı:

chan sisowath

unread,
Feb 9, 2015, 8:42:22 AM2/9/15
to chica...@googlegroups.com
should do the job, as far as i know

you should receive
{normal, timeout}


Mert Öztürk

unread,
Feb 9, 2015, 8:59:51 AM2/9/15
to chica...@googlegroups.com
Hello Chan,

I already changed the boss.config file before and now i check boss_mochicow handler and it is the same as you sent.
My handle close looks like this;

handle_close(Reason, ServiceName, WebSocketId, State) ->
    #state{users=Users} = State,
    io:format("ServiceName ~p, WebSocketId ~p, SessiondId ~p, close for Reason ~p~n",
              [ServiceName, WebSocketId, SessionId, Reason]),
    [{A,B,C,D,E,F,G,H,I,J,K,L,M,N}] = boss_db:find(ip_database,[{web_socket_id,'equals',WebSocketId}]),
    boss_db:delete(B),
    {noreply, #state{users=dict:erase(WebSocketId, Users)}}.

Do i have to add it here?

Thanks
Mert

9 Şubat 2015 Pazartesi 15:42:22 UTC+2 tarihinde mihawk yazdı:

chan sisowath

unread,
Feb 9, 2015, 9:32:24 AM2/9/15
to chica...@googlegroups.com
it should work like you did, since you dont pattern match on Reason
when timeout happen Reason should be equal to {normal, timeout}.

can you check your cowboy version,
websocket was made for cowboy 0.9.0 if i recall,

if your cowboy version is different you should stick to revert 0.9.0
it should work better since there is a small change in cowboy API for websocket.






Mert Öztürk

unread,
Feb 9, 2015, 9:39:53 AM2/9/15
to chica...@googlegroups.com
Hello Chan,

I think thats the case. Now it is working perfectly fine. Thank you for your support :)

Thanks
Mert

9 Şubat 2015 Pazartesi 16:32:24 UTC+2 tarihinde mihawk yazdı:
Reply all
Reply to author
Forward
0 new messages