From 12b1d4bc7e56c7de8bf325f702cff1ae114c4db0 Mon Sep 17 00:00:00 2001 From: Teddy Date: Fri, 23 Aug 2013 20:59:14 +0800 Subject: implemented more in spec --- server/client.py | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) (limited to 'server/client.py') diff --git a/server/client.py b/server/client.py index 40754a9..7ab3c0d 100644 --- a/server/client.py +++ b/server/client.py @@ -7,7 +7,7 @@ from time import sleep def get_hex(data): return "".join([hex(ord(c))[2:].zfill(2) for c in data]) -HOST, PORT = "localhost", 9999 +HOST, PORT = "192.168.1.101", 9990 def gen_auth(username, password): data = pack("!B", 0) @@ -19,28 +19,40 @@ def gen_auth(username, password): def gen_update_location(token, lat, lont): return pack("!BLdd", 2, token, lat, lont) +def gen_request_location(token, gid): + return pack("!BLL", 3, token, gid) + def send(data): try: sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect((HOST, PORT)) - print "sent." +# print "Client " + str(sys.argv[1]) + ": connected" sock.sendall(data) + print get_hex(data) +# print "Client " + str(sys.argv[1]) + ": sent" sock.shutdown(socket.SHUT_WR) +# print "Client " + str(sys.argv[1]) + ": shutdown" received = sock.recv(1024) finally: print "adf" sock.close() - print "Sent".format(get_hex(data)) + print "Sent {}".format(get_hex(data)) print "Received: {}".format(get_hex(data)) return received +#print "Client spawned:" + str(sys.argv[1]) rec = send(gen_auth("hello", "world")) opt, token, status = unpack("!BLB", rec) -print "status:" + str(status) -for i in range(10): - rec = send(gen_update_location(token, random(), random())) - opc, status = unpack("!BB", rec) - print "status:" + str(status) - sleep(10) +rec = send(gen_update_location(token, random(), random())) +opc, status = unpack("!BB", rec) + +rec = send(gen_request_location(token, 1)) +opc, length = unpack("!BL", rec[:5]) +idx = 5 +for i in xrange(length): + uid, lat, lng = unpack("!Ldd", rec[idx:idx + 20]) + print (uid, lat, lng) + idx += 20 +# sleep(60) -- cgit v1.2.3-70-g09d2