0
我在我的VPS 由蟒監聽器(服務器),但是當我給服務器和客戶端VPS和端口8585 的IP addreess此錯誤顯示: 錯誤: socket.error: [Errno 32] Broken pipe
我用Python版本2在VPS 我在我的電腦使用Python版本3的Python socket.error:[錯誤32]破碎管
我的服務器代碼:
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.")`
客戶端:
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)`
謝謝我修正了c.send(),但關於你說的部分「你必須在連接套接字上發送到客戶端而不是在監聽套接字上」,它已經從監聽器發送文本到客戶端了! :|我沒有看到任何問題! –
@MohammadrezaBahari:監聽器沒有連接到任何意味着任何嘗試使用它進行發送的嘗試都會失敗,因爲沒有數據已知的目標。人們只能在連接的套接字(c)上發送數據,即從「accept」返回的數據。 –
現在我明白了,謝謝你。 –