Reputation: 11
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)`
Upvotes: 1
Views: 7411
Reputation: 123270
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, i.e. it should be c.send
instead of s.send
.
Upvotes: 1