how to keep websocket connect until either-side close?
Asked Answered
P

2

5

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

Paulus answered 24/4, 2013 at 3:22 Comment(3)
yes, I have resolved by myself.Paulus
it would be interesting, HOW ;-)Proto
easy, on server side, process PING and PONG message to make the connection alive before timeout, good luckPaulus
S
8

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.

Skinny answered 13/11, 2013 at 18:31 Comment(1)
ws.setReceiveTimeout(Poco::Timespan()); sets it to true infinityHem
D
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

Dietetic answered 24/4, 2013 at 15:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.