如何用加代码可以使TCP客户端的消息发送到TCP服务器上并print出来?
#!/usr/bin/env python
from socket import *
HOST=''
PORT=21567
ADDR=(HOST,PORT)
tcpSerSock=socket(AF_INET,SOCK_STREAM)
tcpSerSock.bind(ADDR)
tcpSerSock.listen(5)
while True:
print 'waiting for connection...'
tcpCliSock,addr=tcpSerSock.accept()
print '...connected from:',addr
while True:
data=tcpCliSock.recv(1024)
if not data:
break
tcpCliSock.send(data)
tcpCliSock.close()
tcpSerSock.close()
#!/usr/bin/env python
from socket import *
HOST='localhost'
PORT=21567
ADDR=(HOST,PORT)
tcpCliSock=socket(AF_INET,SOCK_STREAM)
tcpCliSock.connect(ADDR)
while True:
data=raw_input('>')
if not data:
break
tcpCliSock.send(data)
data=tcpCliSock.recv(1024)
if not data:
break
print data
tcpCliSock.close()
这是我的客户端和服务器代码,我不知道如何下手去改,现在就反馈主机序列号
雷雷 雷雷