# -*- coding: utf-8 -*- import sys sys.path.insert(0, '../../') from netkit.contrib.tcp_client import TcpClient from reimp import Box import time client = TcpClient(Box, '127.0.0.1', 7777, timeout=5) client.connect() box = Box() box.cmd = 1 # box.cmd = 101 box.body = '我爱你' 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
#!/usr/bin/env python # -*- coding: utf-8 -*- import time from websocket import create_connection from websocket import ABNF from reimp import Box ws = create_connection("ws://127.0.0.1:8000/echo") # ws = create_connection("ws://115.28.224.64:8000/echo") box = Box() box.cmd = 101 box.body = '我爱你' t1 = time.time() # 二进制协议 ws.send(box.pack(), ABNF.OPCODE_BINARY) result = ws.recv() print 'time past: ', time.time() - t1 print "Received '%r'" % result recv_box = Box() recv_box.unpack(result) print recv_box ws.close()
# -*- coding: utf-8 -*- from netkit.contrib.tcp_client import TcpClient from reimp import Box import time client = TcpClient(Box, '127.0.0.1', 7777, timeout=5) client.connect() box = Box() box.cmd = 1 #box.cmd = 101 box.body = '我爱你' 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