我遇到套接字编程问题,并且多次查找错误,但是没有找到。请有人帮助我。
服务器代码:
import socket
server_socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
server_socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
server_socket.bind(("localhost",5001)
server_socket.listen(10)
client_socket, address = server_socket.accept()
server_socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
server_socket.bind(("localhost",5001))
server_socket.listen(10)
client_socket, address = server_socket.accept()
while True:
temp = client_socket.recv(100)
print (len(temp))
print ("Recv isn't blocked")
client_socket.close()
客户代码:
import socket
import io
client_socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
client_socket.connect(("localhost",5001))
print("send data finised")
当我运行程序时,虽然客户端没有向服务器发送任何内容,但是服务器上的recv()函数仍在运行,我无法理解为什么,请帮帮我。
答案 0 :(得分:0)
因为您的客户端程序退出,套接字关闭了吗?