import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('localhost', 8021))
s.listen(10)
while True:
conn, addr = s.accept()
print 'got connected from', addr
s.send("sending to client")
conn.close()
s.close()
The problem is as soon i run my client code, it shows "got connected from ('127.0.0.1', 52764)" but then it shows the error
Traceback (most recent call last):
File "D:\Python27\server", line 13, in <module>
s.send("sending to client")
error: [Errno 10057] A request to send or receive data was disallowed because the socket is not connected and (when sending on a datagram socket using a sendto call) no address was supplied
How can I correct it?
My client code is:
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
host = 'localhost'
port = 8021
s.connect((host, port))
revieved = s.recv(1024)
print "Recieved: ", recieved