how to keep websocket connect until either-side close?

时光总嘲笑我的痴心妄想 提交于 2020-01-22 23:57:47

问题


I'd like to build chat app on websocket, and choose Poco C++ lib as webserver (1.4.6p1). There are multiple user at the same time, poco websocket will be blocked at read frame but automatically released after 60 seconds if nothing is received from browser.

I want to keep socket connected in order to manager so many active (or idle) users, but how to get there?

T.H.X


回答1:


I "fixed" the problem with this simple and somewhat dirty line of code:

ws.setReceiveTimeout(Poco::Timespan(10, 0, 0, 0, 0));

Basically, i set the receive timeout to 10 days. Since my websocket will have a lifespan of a few hours, 10 days equals infinity for me.

Hope it helps.




回答2:


Check out this:

Poco::Net Server & Client TCP Connection Event Handler

You have some examples about how wait incomming connections, timeouts, etc.

Good luck



来源:https://stackoverflow.com/questions/16182814/how-to-keep-websocket-connect-until-either-side-close

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!