Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| p:pycli [2017/01/16 08:09] – yehuda | p:pycli [2022/01/03 16:03] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 3: | Line 3: | ||
| def app(): | def app(): | ||
| - | TCP_IP = '------------------------' | + | |
| + | | ||
| + | TCP_IP = ' | ||
| TCP_PORT = 8088 | TCP_PORT = 8088 | ||
| + | |||
| + | # Default buffer | ||
| BUFFER_SIZE = 1024 | BUFFER_SIZE = 1024 | ||
| + | # Open & Connect to socket | ||
| s = socket.socket(socket.AF_INET, | s = socket.socket(socket.AF_INET, | ||
| s.connect((TCP_IP, | s.connect((TCP_IP, | ||
| + | # Recive data - init state | ||
| data = s.recv(BUFFER_SIZE) | data = s.recv(BUFFER_SIZE) | ||
| + | print " | ||
| + | # Check if inited | ||
| if not data.strip() == " | if not data.strip() == " | ||
| print "NOT INITED" | print "NOT INITED" | ||
| Line 16: | Line 25: | ||
| return | return | ||
| - | | + | |
| + | 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 ' | ||
| - | s.send(MSG) | + | |
| + | | ||
| + | # 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 " | ||
| + | # 051 2\n | ||
| + | # 999\n | ||
| data = s.recv(BUFFER_SIZE) | data = s.recv(BUFFER_SIZE) | ||
| - | if not data.strip() == " | + | |
| + | d = data.split(" | ||
| + | |||
| + | if d[-1] == "": | ||
| + | d.remove(d[-1]) | ||
| + | |||
| + | if not d[-1] == " | ||
| print "NOT OK" | print "NOT OK" | ||
| s.close() | s.close() | ||
| return | return | ||
| - | | + | |
| - | s.send(MSG) | + | s.send(" |
| s.close() | s.close() | ||