Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
p:pycli [2017/01/16 08:09] yehudap:pycli [2022/01/03 16:03] (current) – external edit 127.0.0.1
Line 3: Line 3:
  
 def app(): def app():
-    TCP_IP = '------------------------'+    # Write the HOSTs DNS 
 +    TCP_IP = 'tracking-45.poc.alefbt.com' 
 +    TCP_IP = '127.0.0.1' 
     TCP_PORT = 8088     TCP_PORT = 8088
 +
 +    # Default buffer
     BUFFER_SIZE = 1024     BUFFER_SIZE = 1024
  
 +    # Open & Connect to socket
     s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)     s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     s.connect((TCP_IP, TCP_PORT))     s.connect((TCP_IP, TCP_PORT))
  
 +    # Recive data - init state
     data = s.recv(BUFFER_SIZE)     data = s.recv(BUFFER_SIZE)
 +    print "RX", data
 +    # Check if inited
     if not data.strip() == "000":     if not data.strip() == "000":
         print "NOT INITED"         print "NOT INITED"
Line 16: Line 25:
         return         return
  
-    MSG = "010 123\n\+    # Send data 
 +    data = "010 123\n\
 020 XccSSE\n\ 020 XccSSE\n\
 030 1\n\ 030 1\n\
Line 29: Line 39:
 064 60.22\n\ 064 60.22\n\
 999" 999"
 +    # Warning: There is known bug that '999\n' not works
  
-    s.send(MSG)+    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     # 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)     data = s.recv(BUFFER_SIZE)
-    if not data.strip() == "999":+ 
 +    d = data.split("\n") 
 + 
 +    if d[-1] == "": 
 +        d.remove(d[-1]) 
 + 
 +    if not d[-1] == "999":
         print "NOT OK"         print "NOT OK"
         s.close()         s.close()
         return         return
  
-    MSG = "999\n" +    # Reply that got data 
-    s.send(MSG)+    s.send("999\n")
     s.close()     s.close()
  
p/pycli.1484554149.txt.gz · Last modified: (external edit)
Back to top
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0