def tcplink(sock, addr): print 'connected to %s:%s...!' % addr sock.send(Response.json_response(200, [], 'success', '')) while True: data = sock.recv(1024) time.sleep(1) if data == 'exit' or not data: break json_obj = json.loads(data) session_id = json_obj['sessionID'] if json_obj['reqType'] == REQ_TYPE_UPLOAD_LOCATION: updateUserLocation(json_obj['body']) new_data = queryCurrentUsers() str = Response.json_response(200, new_data, 'success', session_id) sock.send(str) print "send -- %s" % str elif json_obj['reqType'] == REQ_TYPE_CREATE_ACCOUNT: body = json_obj['body'] insert_id = createAccount(body['username']) data = {'userID': insert_id} str = Response.json_response(200, data, 'success', session_id) sock.send(str) print "send -- %s" % str # print "send -- Hello %s" % data # sock.send('Hello %s' % data) sock.close() print '%s:%s closed!' % addr