tags:

views:

59

answers:

2

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?

+1  A: 

Put tn.read_until("123", 2) in a loop.

mikerobi
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
So, what happens when the data that arrive are "123\r\n"?
ΤΖΩΤΖΙΟΥ