[Tutor] Network programming

Kent Johnson kent_johnson at skillsoft.com
Mon Sep 20 14:31:30 CEST 2004


Are you using Python 2.3? Prior to 2.3, 'x in y' would throw a TypeError if 
y is a string and x is a string longer than one character.

Is it working sometimes but missing sometimes? If the brsq spans an 
8192-byte boundary you will miss it.

Are you sure the brsq is in the data sent? Maybe it has just a newline 
terminator, or a space after the \x71 or some other difference from what 
you are expecting.

Kent

At 12:41 PM 9/20/2004 +0200, you wrote:
>Hi all ye good people,
>I have a incomming data stream on a socket and are forwarding all the data 
>to a client connection.
>
>I want to look for a certain data sequence in the incomming data and if 
>that is received, the socket connection must be closed. In the following 
>code, newdata is received from a socket server and send out to a client 
>connection self.sock(). Now if 'brsq' is in the data received, the 
>connection 'conn' must be closed. Or the preceeding while loop must be 
>broken. At this stage the 'brsq' is not recognised.
>
>Any suggestions?
>
>Thanks
>Johan
>
>if conn in inFds:
>           newdata = conn.recv(8192)
>       self.log('Newdata recveived in line 129:' + `newdata`)
>         self.sock.send(newdata)
>
>       brsq = '\x71\x0D\0A'
>
>       if brsq in newdata:
>           self.log('Break signal received on line 134' + `newdata`)
>           break
>
>           else:
>            continue
>



More information about the Tutor mailing list