我的目标是每次客户端向服务器发送数据时,服务器都会显示它。但是目前当客户端发送数据时,服务器捕获数据并仅在第一次显示。是什么导致了问题?顺便说一句,这是我第一次做网络编程,所以请保持你的答案简单。
服务器脚本
import socket
server_socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
server_socket.bine(("",5001))
server_socket.listen(5)
print "TCP Server Waiting for incoming client connection on port 5001..."
while True:
client_socket, address =server_socket.accept()
print "Connection from ", address
data = client_socket.recv(512)
print "RECIEVED:" , data
客户端脚本
import socket
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client_socket.connect(('169.254.0.1', 5001))
data=''
while data!='quit':
data = raw_input ( "SEND :" )
client_socket.send(data)