0

I want to interactively connect to a telnet server in Python and be able to both read and write text to the server. I am trying the following code to connect:

import telnetlib
host = telnetlib.Telnet("mud.accursed-lands.com",8000)
host.read_very_eager()

But when I do this nothing happends. If I wrap the host.read_very_eager() in print then I get b'', which I think represents an empty bit.

How can I interactively connect to this server?

chopper draw lion4
  • 12,401
  • 13
  • 53
  • 100
  • `b` is actually a [bytes](https://docs.python.org/3.4/library/stdtypes.html#binaryseq) class. – James Mertz Aug 05 '14 at 16:31
  • And you can connect and get text back immediately if you connect manually to the MUD, with the *standard* telnet client? – Some programmer dude Aug 05 '14 at 16:31
  • possible duplicate of [Accessing a telnet session in python](http://stackoverflow.com/questions/19845525/accessing-a-telnet-session-in-python) – Robᵩ Aug 05 '14 at 17:17
  • By "interactively", do you refer to the interaction between your Python script and the mud server? Or do you refer to the interaction between your human user and the mud server? – Robᵩ Aug 05 '14 at 17:17
  • Between human user and mud server – chopper draw lion4 Aug 05 '14 at 17:19
  • Then the duplicate I mentioned won't help you. It describes how to get your Python program to interact with a telnet server. – Robᵩ Aug 05 '14 at 17:24
  • 1
    By the way, your code snippet produces an expected output. `.read_very_eager()` returns only whatever data has already been received, with no waiting. By the time you have called `.read_very_eager()`, nothing has yet been received. To demonstrate this, add "time.sleep(1)" before the call to `.read_very_eager()`. – Robᵩ Aug 05 '14 at 17:28
  • How do you make it so you are receiving a constant stream of input? It's hard to believe what I am doing is as difficult as it is. I mean, I essentially just want to achieve what is easily doable in terminal by typeing "telnet host:port", but I want to do it in Python instead of in terminal. – chopper draw lion4 Aug 05 '14 at 17:30
  • How is your program interacting with the human user? Graphically? Through `print()`/`raw_input()`? – Robᵩ Aug 05 '14 at 17:30
  • Yeah, print()/raw_input() – chopper draw lion4 Aug 05 '14 at 17:30
  • Your code works perfectly for me as well, getting the expected output – deinonychusaur Aug 05 '14 at 17:40

0 Answers0