尝试使用python创建简单的TCP客户端/服务器连接,并且在运行python脚本时,我们遇到了管道破裂的错误,您是否在我的代码中看到任何会导致此错误显示的错误,谢谢: )
客户代码
import socket
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
ip = "HIDDEN"
print ip
port = HIDDEN
address = (ip, port)
client.connect(address)
client.send("HELLO")
client.recv(2048)
print client.recv(2048)
服务器代码
import socket
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
IP = "HIDDEN"
PORT = HIDDEN
ADDRESS = (IP, PORT)
server.bind(ADDRESS)
server.listen(1)
print "Started Listening for connection on IP ", IP, " and port number ", PORT
client,addr = server.accept()
print "Got connection from IP ", addr[0], "and port ", addr[1]
while True:
ConnectionInfo = client.recv(2048)
if(ConnectionInfo =="HELLO"):
client.send("Hello to you as well")
elif(ConnectionInfo == "Goodbye"):
client.send("Goodbye to you as well")
client.close()
break
else:
client.send("invalid keyword, please try again")
client.close()
server.shutdown()
server.close()