def handle(uid): # client = TcpClient(Box, '192.168.1.67', 29000, timeout=None) client = TcpClient(Box, '115.28.224.64', 29000, timeout=None) client.connect() box = Box() box.cmd = 1 box.set_json(dict( uid=uid )) client.write(box) box = Box() box.cmd = 2 box.set_json(dict( uid=uid )) client.write(box) t1 = time.time() while True: # 阻塞 box = client.read() print 'time past: ', time.time() - t1 print box if not box: print 'server closed' break
def handle(uid): # client = TcpClient(Box, '192.168.1.67', 29000, timeout=None) client = TcpClient(Box, '115.28.224.64', 29000, timeout=None) client.connect() box = Box() box.cmd = 1 box.set_json(dict(uid=uid)) client.write(box) box = Box() box.cmd = 2 box.set_json(dict(uid=uid)) client.write(box) t1 = time.time() while True: # 阻塞 box = client.read() print 'time past: ', time.time() - t1 print box if not box: print 'server closed' break
def handle(uid): client = TcpClient(Box, '127.0.0.1', 29000, timeout=None) client.connect() box = Box() box.cmd = 100 box.set_json(dict( uid=uid )) client.write(box) t1 = time.time() while True: # 阻塞 box = client.read() print 'time past: ', time.time() - t1 print box if not box: print 'server closed' break
def handle(uid): client = TcpClient(Box, config.GATEWAY_OUTER_HOST, config.GATEWAY_OUTER_PORT, timeout=None) client.connect() box = Box() box.cmd = 2 # box.cmd = 999 box.set_json(dict(uid=uid)) client.write(box) t1 = time.time() while True: # 阻塞 box = client.read() print 'time past: ', time.time() - t1 print box if not box: print 'server closed' break
# -*- coding: utf-8 -*- from netkit.box import Box box1 = Box() box1.set_json(dict(uin=1, name=u'我')) print box1 print repr(box1.pack()) print box1.body buf = box1.pack() box2 = Box() for i in range(0, len(buf)+1): tmp_buf = buf[0:i] if box2.unpack(tmp_buf) > 0: print box2 print box2.get_json() break