开发者

EOL character in Linux and Windows

开发者 https://www.devze.com 2022-12-22 14:43 出处:网络
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'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..

0

精彩评论

暂无评论...
验证码 换一张
取 消