点击(此处)折叠或打开
- import socket
- from threading import Thread
- import sys
- sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- port = input("port: ")
- sock.connect(('localhost', port))
- def reader():
- while 1:
- buf = sock.recv(1024)
- if buf:
- for b in buf: print hex(ord(b)),
- def writer():
- while 1:
- buf = raw_input()
- sock.send(buf)
-
- r=Thread(target=reader,args=())
- w=Thread(target=writer,args=())
- r.start()
- w.start()