- Code: Select all
connectedWebsocket.reset(new Poco::Net::WebSocket(request, response));
...
// Set a receive timeout for this socket
Poco::Timespan timeout(
WebSocketRecvTimeoutSeconds,
WebSocketRecvTimeoutMicroSeconds);
connectedWebsocket->setReceiveTimeout(timeout);
char buffer[1024];
int flags = 0;
int n = 0;
do
{
SendLiveMessages(connectedWebsocket.get(), Poco::Net::WebSocket::FRAME_TEXT);
try
{
// Listen for frames from client
n = connectedWebsocket->receiveFrame(buffer, sizeof(buffer), flags);
}
catch(Poco::Net::WebSocketException&)
{
// Must terminate the connection
flags |= Poco::Net::WebSocket::FRAME_OP_CLOSE;
}
catch(Poco::TimeoutException& tex)
{
// Normal - didn't receive any frames this timeout
// period. Nothing to do.
}
}
while ((flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) !=
Poco::Net::WebSocket::FRAME_OP_CLOSE);
This works as intended except the timeout is 60 seconds regardless of what I set it to (I have WebSocketRecvTimeoutSeconds=2 and WebSocketRecvTimeoutMicroSeconds=0).
Platform WinCE 6.0 R3
Although WinCE doesn't support SO_RCVTIMEO the Poco documentation for setReceiveTimeout states that it works on platforms which don't support it, right?
setReceiveTimeout
void setReceiveTimeout(
const Poco::Timespan & timeout
);
Sets the send timeout for the socket.
On systems that do not support SO_RCVTIMEO, a workaround using poll() is provided.
Alternatively could I use 2 separate threads, one to receive and one to send on the socket as I might with a normal TCP socket?
Thanks in advance!





