Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
假设您通过套接字连接连接到服务器,并且有一次您将请求发送到服务器并接收响应,然后您再次尝试将请求发送到服务器但是 send(); 返回-1,因为服务器在一段时间后服务器关闭,您可以使用相同的套接字向服务器发送请求吗?
不,当您收到错误时,连接不再有效。一旦连接失效,您应该关闭套接字;您不能将其重新用于新连接。如果服务器宕机了,它不记得原始连接的参数(例如端口号);您需要打开一个新连接,以便客户端和服务器同步。