我正在尝试运行客户端serevr套接字,但是我收到以下错误 客户代码
enter code here
#!/usr/bin/env python3
import socket
HOST = '127.0.0.1' # The server's hostname or IP address
PORT = 65432 # The port used by the server
s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
d=input("enter numbers")
f=input("enter numbers")
val = str(d) # sep = ' ' or sep = `\n`
s.send(val)
val1 = str(f) # sep = ' ' or sep = `\n`
s.send(val1)
#s.send(d)
#s.send(f)
data = s.recv(1024)
data5=int(data)
print('Received', repr(data5))
s.close()
server
#!/usr/bin/env python3
import socket
HOST = '127.0.0.1' # Standard loopback interface address (localhost)
PORT = 65432 # Port to listen on (non-privileged ports are > 1023)
s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT))
s.listen(PORT)
conn, addr = s.accept()
with conn:
print('Connected by', addr)
while True:
w1 = conn.recv(1024)
w2= conn.recv(1024)
#w1=int(w[0])
#w2=int(w[1])
data3=w1-w2
data3=str(data3)
if not data:
break
conn.sendall(data3)
conn.close()
error-socket.error:[Errno 32]管道损坏 我遇到了这个错误,我们可以解决这个问题吗,我想我们在tcp连接关闭时遇到了问题。