我已经成功地将文件内容(图像)复制到新文件中.但是,当我在TCP套接字上尝试相同的事情时,我遇到了问题.服务器循环未退出.客户端循环在到达EOF时退出,但服务器无法识别EOF.
这是代码:
服务器
import socket # Import socket module
s = socket.socket() # Create a socket object
host = socket.gethostname() # Get local machine name
port = 12345 # Reserve a port for your service.
s.bind((host, port)) # Bind to the port
f = open('torecv.png','wb')
s.listen(5) # Now wait for client connection.
while True:
c, addr = s.accept() # Establish connection with client.
print 'Got connection from', addr
print "Receiving..."
l = c.recv(1024)
while (l):
print "Receiving..."
f.write(l)
l = …Run Code Online (Sandbox Code Playgroud)