I have a problem here with this code. I'm opening a socket, then listening to it with a while loop. I send data from a php script with
socket_write($sock, $test, $len);
It works very well, but when I send several writes in a row, the Python script handles some of the writes as just one write.
import socket
HOST = 'localhost' # the host
PORT = 12126 # the port
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT))
while 1:
s.listen(0)
conn, addr = s.accept()
print 'Connected by', addr
while 1:
data = conn.recv(1024)
if not data: break
conn.close()
I'm looking for a way to listen to that port and get one write after another.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…