0

我有一个socket编程的问题,花了很多时间寻找错误,但没有找到。有人可以帮我吗,拜托。

服务器代码:

 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() 函数仍在运行,我不明白为什么,请帮助我。

4

1 回答 1

0

因为您的客户端程序退出,套接字已关闭?

于 2012-07-30T09:17:18.637 回答