vsajip / pywebsocket

Automatically exported from code.google.com/p/pywebsocket
0 stars 0 forks source link

Msgutil reduce read timeout #64

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Hi,

how can I change the value for the read timeout in msgutil.receive_message in 
my websockethandler?
I'm new in python and wasn't able to figure it out, so I would be thankful if 
someone can give me a hint.

Regards
Jan

Original issue reported on code.google.com by jstuhlm...@gmail.com on 25 Aug 2010 at 9:01

GoogleCodeExporter commented 9 years ago
msgutil is passed a request object in the constructor this object contains a 
socket you can set a read timeout on.

I'm using standalone.py which has the following method. I added the line 
socket_.settimeout(2.0) which gives me a timeout on the socket. I found this 
useful to stop my code waiting for input if I attempted to read from a socket 
when there was no data to read. This throws a timeout exception you will need 
to catch. This is a pretty hacky way to do this but I am new to Python and was 
not sure how else to do this. If anyone else has a better way please share it.

 def _create_socket(self):
        socket_ = socket.socket(self.address_family, self.socket_type)
        socket_.settimeout(2.0)
        if WebSocketServer.options.use_tls:
            ctx = OpenSSL.SSL.Context(OpenSSL.SSL.SSLv23_METHOD)
            ctx.use_privatekey_file(WebSocketServer.options.private_key)
            ctx.use_certificate_file(WebSocketServer.options.certificate)
            socket_ = OpenSSL.SSL.Connection(ctx, socket_)
        return socket_

Original comment by tristanw...@gmail.com on 11 Oct 2010 at 1:24

GoogleCodeExporter commented 9 years ago

Original comment by tyoshino@chromium.org on 17 Dec 2010 at 8:05