1

I'm using telnet lib to read from an Telnet server.

my code looks like this:

 s = telnetlib.Telnet(self.host, self.port)
 while 1:
     line = s.read_until("\n")
     print(line)

this is working fine so far, but as i have a look on the network traffic i can see tons of packets between client and server. If i use raw socket, this is not happening.

packets on the network are nearly empty. I Guess this is a pull for next charakter

Has anybody an explanation for this? I don't whant to spam my telnet server but i like the idea of the read_until mechanism since i can get line by line.

thanks!

maazza
  • 7,016
  • 15
  • 63
  • 96
Vinzens
  • 21
  • 1

2 Answers2

0

It seems that your Telnet server works in non-buffered mode (sends not the entire line, but rather each symbol in a separate packet). You probably need to change you server settings so it can work in a buffered mode.

Also, you may see:

  • a lot of packets from telnet client back to server. These are echos of all commands and it's pretty normal
  • Small packets with new line symbols like \n\n\r

EDIT:

Another possible cause is polling, you may try this:

import sys
import select
del select.poll
import telnetlib

tn = telnetlib.Telnet('10.32.137.39', 3008)

while 1:
    line = s.read_until("\n")
    print(line)

To say something more specific it would be great to see Wireshark trace of the traffic

Konstantin
  • 2,937
  • 10
  • 41
  • 58
  • Solved it by using:
    import socket
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.connect((self.host, self.port))
    for i in s.makefile('r'):
        print("FOO " + i)
    
    – Vinzens Apr 14 '14 at 10:09
0

Solved it by using:

import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((self.host, self.port))
for i in s.makefile('r'):
    print("FOO " + i)
Vinzens
  • 21
  • 1