Re: need a thread to keep a socket connection alive?

2006-04-25 Thread Ben Sizer
[EMAIL PROTECTED] wrote: the data comming in is alway in 158 bytes though. And one day it may not. :) Consider yourself warned! (In a friendly manner.) -- Ben Sizer -- http://mail.python.org/mailman/listinfo/python-list

Re: need a thread to keep a socket connection alive?

2006-04-25 Thread nephish
yeah, he he -- http://mail.python.org/mailman/listinfo/python-list

Re: need a thread to keep a socket connection alive?

2006-04-24 Thread Ben Sizer
[EMAIL PROTECTED] wrote: i have a script that waits for message packets from a data server over a socket. If you're using TCP, bear in mind that you do not receive packets - you receive a stream of data, which may usually come in the same quantities as it was sent, but not always. If you don't

Re: need a thread to keep a socket connection alive?

2006-04-24 Thread Roy Smith
[EMAIL PROTECTED] wrote: hey there, i have a script that waits for message packets from a data server over a socket. it goes a little like this: while 1: x+=1 databack = sockobj.recv(158) if databack: print 'caught a message %s bytes ' %

Re: need a thread to keep a socket connection alive?

2006-04-24 Thread Fredrik Lundh
Roy Smith wrote: If you want to read fixed-length messages (as you appear to be trying to do with your recv(158)), you need to build a buffering layer which reads from the socket into a buffer and then doles out messages to a higher layer from that buffer. This is not a trivial problem. By

Re: need a thread to keep a socket connection alive?

2006-04-24 Thread Roy Smith
Fredrik Lundh [EMAIL PROTECTED] wrote: however, creating a buffered layer for reading is a trivial problem: just call makefile on the socket object, and use the resulting object as a file handle: The problem with that is that makefile() requires the socket to be in blocking mode. If you're

Re: need a thread to keep a socket connection alive?

2006-04-24 Thread Serge Orlov
[EMAIL PROTECTED] wrote: hey there, i have a script that waits for message packets from a data server over a socket. it goes a little like this: while 1: x+=1 databack = sockobj.recv(158) if databack: print 'caught a message %s bytes ' %

Re: need a thread to keep a socket connection alive?

2006-04-24 Thread Roy Smith
Serge Orlov [EMAIL PROTECTED] wrote: sockobj.settimeout(550) [...] Also, as other people pointed out, you'd better make buffered socket with .makefile() socket method. If I understand the docs for the socket module correctly, these two suggestions are mutually incompatable. --

Re: need a thread to keep a socket connection alive?

2006-04-24 Thread Serge Orlov
Roy Smith wrote: Serge Orlov [EMAIL PROTECTED] wrote: sockobj.settimeout(550) [...] Also, as other people pointed out, you'd better make buffered socket with .makefile() socket method. If I understand the docs for the socket module correctly, these two suggestions are mutually

Re: need a thread to keep a socket connection alive?

2006-04-24 Thread nephish
ok, thanks for all the suggestions, gents, i clearly have more to read on this. i have discovered that the server will send a request for the heartbeat ping if its almost timed out, so i use the length of the message to determine what to do with it. msg = sockobj.recv(1024) if len(msg) == 158:

Re: need a thread to keep a socket connection alive?

2006-04-24 Thread Roy Smith
[EMAIL PROTECTED] wrote: elif len(msg) == (34): # length of request for ping ping the server This seems really dangerous. You are obviously writing to some already defined (and hopefully, documented) protocol. What does the protocol spec say about ping request messages? I would be very

Re: need a thread to keep a socket connection alive?

2006-04-24 Thread Rene Pijlman
[EMAIL PROTECTED]: i have discovered that the server will send a request for the heartbeat ping if its almost timed out, so i use the length of the message to determine what to do with it. msg = sockobj.recv(1024) if len(msg) == 158: record the data elif len(msg) == (34): # length of request

Re: need a thread to keep a socket connection alive?

2006-04-24 Thread nephish
ok, every message starts with ENX and ends with STX in between are several parts. the first is the message length sent as an unsigned long int (according to the docs) this is four bytes. The next is the message type - another 4 bytes that corrospond to a certain chart. for example, the login is

Re: need a thread to keep a socket connection alive?

2006-04-22 Thread Rene Pijlman
[EMAIL PROTECTED]: i have a script that waits for message packets from a data server over a socket. Using what network protocol? it works fine for a while, but the server requires that i send a heartbeat ping every 600 seconds or it will terminate the connection. [...] should i do this with

Re: need a thread to keep a socket connection alive?

2006-04-22 Thread nephish
thanks for the info, i will likely use the first link you posted with the async module just to get it going, but i want to learn more about twisted for later. there is even an O'Reilly book on it i see. thanks for the tips, sk -- http://mail.python.org/mailman/listinfo/python-list