import socket
 
def app():
    # Write the HOSTs DNS
    TCP_IP = 'tracking-45.poc.alefbt.com'
    TCP_IP = '127.0.0.1'
 
    TCP_PORT = 8088
 
    # Default buffer
    BUFFER_SIZE = 1024
 
    # Open & Connect to socket
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.connect((TCP_IP, TCP_PORT))
 
    # Recive data - init state
    data = s.recv(BUFFER_SIZE)
    print "RX", data
    # Check if inited
    if not data.strip() == "000":
        print "NOT INITED"
        s.close()
        return
 
    # Send data
    data = "010 123\n\
020 XccSSE\n\
030 1\n\
040 +55-1-565-5656\n\
051 1\n\
052 80\n\
053 50\n\
054 120\n\
061 1\n\
062 31.8912434\n\
063 34.8127223\n\
064 60.22\n\
999"
    # Warning: There is known bug that '999\n' not works
 
    print "TX",data
    s.send(data)
 
    # get data from server (include updates)
    # and should ends with 999\n
    #
    # If UPDATES not exists. see the spec
    #
    # Can be "update of rate", the data looks like that:
    #    051 2\n
    #    999\n
    data = s.recv(BUFFER_SIZE)
 
    d = data.split("\n")
 
    if d[-1] == "":
        d.remove(d[-1])
 
    if not d[-1] == "999":
        print "NOT OK"
        s.close()
        return
 
    # Reply that got data
    s.send("999\n")
    s.close()
 
 
app()
p/pycli.txt · Last modified: 2022/01/03 16:03 by 127.0.0.1
Back to top
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0