Overview
Features
Download
Documentation
Community
Add-Ons & Services

setReceiveTimeout on WebSocket

Please post support and help requests here.

setReceiveTimeout on WebSocket

Postby clay » 18 Jan 2013, 01:10

Hi, new Poco user here and so far I am impressed! I am having trouble setting a receiveTimeout on a WebSocket however. Is there a minimum allowed? I modified the sample and am trying to use a single thread to attempt to receive for a couple seconds in order to listen for close requests, and then push data from the server to the client.
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!
clay
 
Posts: 3
Joined: 18 Jan 2013, 01:00

Re: setReceiveTimeout on WebSocket

Postby alex » 20 Jan 2013, 07:42

clay wrote:Although WinCE doesn't support SO_RCVTIMEO the Poco documentation for setReceiveTimeout states that it works on platforms which don't support it, right?

I skimmed through the code and it looks like that's true for generic SocketImpl but not for WebSocketImpl::receiveBytes(). I did not write that code and I'd have to look a bit deeper to understand exactly why. Günter may be able to shed some light on it if he stops by here.
alex
 
Posts: 1130
Joined: 11 Jul 2006, 16:27
Location: United_States

Re: setReceiveTimeout on WebSocket

Postby clay » 21 Jan 2013, 17:44

Thanks for the response! It would still be nice to know the answer to this, but I switched to a 2 threaded approach without much complication.
clay
 
Posts: 3
Joined: 18 Jan 2013, 01:00

Re: setReceiveTimeout on WebSocket

Postby guenter » 21 Jan 2013, 18:37

This seems to be a bug - WebSocketImpl needs to override setReceiveTimeout(), etc. and forward to internal StreamSocketImpl in case POCO_BROKEN_TIMEOUTS is defined.
guenter
 
Posts: 1135
Joined: 11 Jul 2006, 16:27
Location: Austria


Return to Support

Who is online

Users browsing this forum: No registered users and 2 guests

cron