Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to keep websocket connect until either-side close?

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

like image 411
tiplip Avatar asked Apr 24 '13 03:04

tiplip


2 Answers

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.

like image 114
yiown Avatar answered Sep 19 '22 18:09

yiown


Check out this:

Poco::Net Server & Client TCP Connection Event Handler

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

Good luck

like image 40
Cesar Ortiz Avatar answered Sep 21 '22 18:09

Cesar Ortiz