服务端代码:
from SocketServer import BaseRequestHandler,TCPServer
class EchoHandler(BaseRequestHandler):
def handler(self):
print "Got connection from",self.client_address
while True:
msg=self.request.recv(1024)
print "recv:",msg
if not msg:
break
self.request.send(msg)
if __name__=="__main__":
server=TCPServer(('127.0.0.1',20000),EchoHandler)
server.serve_forever()
from socket import socket,AF_INET,SOCK_STREAM
print "Go"
s=socket(AF_INET,SOCK_STREAM)
s.connect(('localhost',20000))
print s.send('Hellow world')
print s.recv(1024)
Go
12
为什么会返回12呢。?
结果很蛋疼:
handler应该为handle
..