another question about buffers

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • nephish@xit.net

    #1

    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(s ocket.AF_INET, socket.SOCK_STR EAM)
    sockobj.connect ((serverhost,se rverport))
    login = 'STXusernamepas swordETX'
    sockobj.send(lo gin)
    login_ack = sockobj.recv(10 28)
    if login_ack:
    print 'received login_ack'
    else:
    print 'login failure'



    req = "STXsendreq ETX"
    sockobj.send(re q) # send request for data stream

    databack = sockobj.recv(10 28)
    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

  • Lawrence D'Oliveiro

    #2
    Re: another question about buffers

    In article <1145645420.014 839.260540@g10g 2000cwb.googleg roups.com>,
    nephish@xit.net wrote:
    [color=blue]
    >databack = sockobj.recv(10 28)
    >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.[/color]

    Perhaps the string you are receiving back on the second recv is being
    interpreted as False.

    Comment

    • nephish@xit.net

      #3
      Re: another question about buffers

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

      Comment

      • Lawrence D'Oliveiro

        #4
        Re: another question about buffers

        In article <1145711394.139 083.275100@i39g 2000cwa.googleg roups.com>,
        nephish@xit.net wrote:
        [color=blue]
        >i think it may be,[/color]

        Moral: don't use arbitrary values as booleans.

        Comment

        Working...