another question about buffers

N

nephish

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
 
L

Lawrence D'Oliveiro

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.
 
N

nephish

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top