Project

General

Profile

Statistics
| Revision:

root / branches / library_refactor / projects / mapping / python / colony.py @ 1390

History | View | Annotate | Download (913 Bytes)

1 902 tachim
#!/usr/bin/env python3.0
2
import sys, time
3
from socket import *
4 918 tachim
from struct import *
5 902 tachim
6
hostname='localhost'
7
8
def inp(str):
9
    return input(str).encode('ascii')
10
11
def main():
12
13 918 tachim
    funcs = {1 : 'print_range_info'}
14 902 tachim
15
    buf = []
16
    sock = socket()
17
    sock.connect((hostname, int(sys.argv[1])))
18
19
    while (True):
20
        buf = sock.recv(100)
21
22
        if (buf):
23
            type = buf[2]
24
            if type in funcs.keys():
25
                globals()[funcs[type]](buf)
26
27
28
def print_range_info(packet):
29
    print ('Info from %d' % packet[0])
30 918 tachim
31 902 tachim
    src = packet[0]
32
33 918 tachim
    packet_length = packet[1]
34 902 tachim
35 918 tachim
    data = packet[3 : 3+packet_length]
36
    print("data length: %d" % len(data))
37
    ranges = unpack('hhhhhhh',data)
38 902 tachim
39 918 tachim
    print(ranges)
40
41
42 902 tachim
if __name__=='__main__':
43
44
    if len(sys.argv) < 2 or not str.isdecimal(sys.argv[1]):
45
        print("Usage: %s <portno>" % sys.argv[0])
46
        sys.exit()
47
48
    main()