im just getting into the networking and i wanted to try something with pinging
server code:
import socket
host = 'localhost'
port = 5050
backlog = 5
size = 1024
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((host,port))
s.listen(backlog)
while 1:
client, address = s.accept()
data = client.recv(size)
print "getting "+str(data)+" from "+ str(address)
client code
import socket
import time
host = 'localhost'
port = 5050
size = 1024
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host,port))
while 1:
s.send('PING')
print "sending package"
time.sleep(1)
now it outputs:
getting PING from ('127.0.0.1', 56580)
only once, while it should get a PING every second.
how can i fix this?
As you only make one connection to your server, you only need to call
.accept()once, to accept that connection. Once open, the socket will receive the periodic packets you send from your client.