Sockets and time-outs 
Author Message
 Sockets and time-outs

I'm using the socket module for a program, but there's one thing that I want
to improve on it.
The client side of this sends data to the server and always get a reply
back, but sometimes the server sends something that wasn't requested of the
reply comes in two sends. Thus I need to read the socket sometimes to see if
there's something waiting. Using recv() is great for getting a reply I know
is there, but when using it and there's no message there it takes an awfully
long time to time out and waiting for this time-out blocks the sending on
the same socket. Is there any way to set a shorter time-out (basically just
check for 2 secs or so) or is there an other function for this?
Regards
Ulf


Fri, 31 Jan 2003 03:00:00 GMT  
 Sockets and time-outs

| I'm using the socket module for a program, but there's one thing that I want
| to improve on it.
| The client side of this sends data to the server and always get a reply
| back, but sometimes the server sends something that wasn't requested of the
| reply comes in two sends. Thus I need to read the socket sometimes to see if
| there's something waiting. Using recv() is great for getting a reply I know
| is there, but when using it and there's no message there it takes an awfully
| long time to time out and waiting for this time-out blocks the sending on
| the same socket. Is there any way to set a shorter time-out (basically just
| check for 2 secs or so) or is there an other function for this?

I would use select, like this for a very simple example:

    import select
    ...
    input = [srv_con]
    input, output, error = select.select(input, [], [], 2.0)
    if srv_con in input:
        srv_input = srv_con.recv(8192)

Now depending on your protocol, it may be convenient to put this select
in a very central place in the system.  Protocols like that, where the
dialogue doesn't simply trade back and forth, are somewhat more challenging.




Fri, 31 Jan 2003 03:00:00 GMT  
 Sockets and time-outs


Quote:

>I'm using the socket module for a program, but there's one thing that I want
>to improve on it.
>The client side of this sends data to the server and always get a reply
>back, but sometimes the server sends something that wasn't requested of the
>reply comes in two sends. Thus I need to read the socket sometimes to see if
>there's something waiting. Using recv() is great for getting a reply I know
>is there, but when using it and there's no message there it takes an awfully
>long time to time out and waiting for this time-out blocks the sending on
>the same socket. Is there any way to set a shorter time-out (basically just
>check for 2 secs or so) or is there an other function for this?

select is probably the best option in this case, but you might also take
a look at http://www.*-*-*.com/
--

Androgynous poly {*filter*} vanilla {*filter*} het    <*>     http://www.*-*-*.com/
Hugs and backrubs -- I break Rule 6

Gun-toting Naderite / socialized medicine libertarian



Fri, 31 Jan 2003 03:00:00 GMT  
 Sockets and time-outs
A coworker of mine, Tim O'malley has recently written
a package for timeouts on sockets. It basically
overrides the existing sockes library and lets you
set timeouts as desired, as if the base libraries
had this magic functionality.


        -pehr

Quote:

> I'm using the socket module for a program, but there's one thing that I want
> to improve on it.
> The client side of this sends data to the server and always get a reply
> back, but sometimes the server sends something that wasn't requested of the
> reply comes in two sends. Thus I need to read the socket sometimes to see if
> there's something waiting. Using recv() is great for getting a reply I know
> is there, but when using it and there's no message there it takes an awfully
> long time to time out and waiting for this time-out blocks the sending on
> the same socket. Is there any way to set a shorter time-out (basically just
> check for 2 secs or so) or is there an other function for this?
> Regards
> Ulf



Mon, 03 Feb 2003 12:38:54 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. socket and timeout

2. sockets and timeout

3. TCP Socket and timeout problem

4. How can I catch socket read timeouts?

5. HELP: socket.connect timeout

6. 1)Sockets and Timeout/ 2) TFTP

7. socket connection timeout and http_get

8. catch socket connect timeouts in tcl 7.5

9. Avoiding long time-outs when reusing sockets in SocketServer

10. Print outs of Richtext Streams

11. Macro and struct call-outs from Eiffel

12. How to use INS OUTS in pentium CPU??

 

 
Powered by phpBB® Forum Software