470,841 Members | 1,058 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,841 developers. It's quick & easy.

another question about buffers

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
3 962
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
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
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.

Similar topics

2 posts views Thread by DrBob | last post: by
18 posts views Thread by JG | last post: by
reply views Thread by Sam Durai | last post: by
4 posts views Thread by OhKyu Yoon | last post: by
3 posts views Thread by Michel Esber | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.