简体   繁体   English

Python socket.error:[Errno 32]管道损坏

[英]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 我在vps上制作了一个python侦听器(服务器),但是当我向服务器和客户端提供vps的IP地址和端口8585时,此错误显示:error: socket.error: [Errno 32] Broken pipe我在vps中使用python版本2我在PC上使用python版本3

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 . 你必须做好send的连接插座上的客户端,而不是在监听套接字,即它应当c.send代替s.send

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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