简体   繁体   中英

Python socket.error: [Errno 32] Broken pipe

i made a python listener(server) on my vps but when i give the server and client the ip addreess of vps and port 8585 this error shows: error : socket.error: [Errno 32] Broken pipe i use python version 2 in vps i use python version 3 in my PC

my server code :

import socket
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
ip = raw_input("ip : ")
ip = str(ip)
port = raw_input("port : ")
port = int(port)
s.bind((ip,port))
s.listen(5)
while True:
    c, addr = s.accept()
    s.send("welcome !")
    print (addr, "connected.")`

client :

import socket
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
HOST = input("HOST : ")
HOST = str(HOST)
PORT = input("PORT : ")
PORT = int(PORT)
s.connect((HOST,PORT))
buff = 1024
data = s.recv(buff)
print(data)`

In the server you have:

 c, addr = s.accept() s.send("welcome !") 

You must do the send on the connected socket to the client and not on the listener socket, ie it should be c.send instead of s.send .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM