By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,559 Members | 1,154 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,559 IT Pros & Developers. It's quick & easy.

another question about buffers

P: n/a
lo there all !

i finally got my script to receive info on a socket. but i need to
somehow set up a loop that will continue to listen for more info
comming across the same socket.

the way it works is, i log in with a login and password, it shoots back
an acknowlagement, then i send a request for data. every so often it
will send a packet of data that i need to record. i know how to receive
once, but i dont know how to go back to receive again.

the messages all start with "STX" and end with "ETX"

here is what i have so far. (it isn't working very well)

#set a socket to communicate with the server
serverhost = '10.10.10.4'
serverport = 9550

print 'connecting to server'
sockobj = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sockobj.connect((serverhost,serverport))
login = 'STXusernamepasswordETX'
sockobj.send(login)
login_ack = sockobj.recv(1028)
if login_ack:
print 'received login_ack'
else:
print 'login failure'

req = "STXsendreqETX"
sockobj.send(req) # send request for data stream

databack = sockobj.recv(1028)
if databack:
print 'caught a message %s bytes ' % len(databack)
else:
print 'fail to recieve data from server'

the output in the terminal runs fine until it fails to get the
databack, it prints out the "fail to receive from server" bit.

anything obvious that i am missing here?

thanks

Apr 21 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
In article <11**********************@g10g2000cwb.googlegroups .com>,
ne*****@xit.net wrote:
databack = sockobj.recv(1028)
if databack:
print 'caught a message %s bytes ' % len(databack)
else:
print 'fail to recieve data from server'

the output in the terminal runs fine until it fails to get the
databack, it prints out the "fail to receive from server" bit.


Perhaps the string you are receiving back on the second recv is being
interpreted as False.
Apr 22 '06 #2

P: n/a
i think it may be,
i am just doing a while 1: loop to just wait for whatever comes in.
thanks

Apr 22 '06 #3

P: n/a
In article <11**********************@i39g2000cwa.googlegroups .com>,
ne*****@xit.net wrote:
i think it may be,


Moral: don't use arbitrary values as booleans.
Apr 22 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.