I'm writing a simple script, that just connects to telnet port, listens everything on it, staying connected and when some string, for example '123' appears, script do something. I use tn.read_until("123", 2), but when '123' appears, script just disconnects. How to make it stay online?
A:
You can try this:
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('', 21))
s.listen(1)
conn = s.accept()
run = True
while run==True:
data = conn.recv(1000)
if data == '123':
#do something
else:
#do something
conn.close()
is this what you want..
Rami Jarrar
2010-03-12 16:00:23
So, what happens when the data that arrive are "123\r\n"?
ΤΖΩΤΖΙΟΥ
2010-04-07 15:17:19