EOL character in Linux and Windows
I'm writing a simple script, that just connects to telnet port, listens everything on it, staying connected and when some string, fo开发者_Python百科r 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?
Put tn.read_until("123", 2) in a loop.
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..
精彩评论