telnetlib3 icon indicating copy to clipboard operation
telnetlib3 copied to clipboard

Telnet server example doesn't work

Open rugubara opened this issue 1 year ago • 1 comments

the overall lack of documentation for the server part led me to try the example code verbatim. The snippet completes, instead of waiting for a connection.

import asyncio, telnetlib3

async def shell(reader, writer):
    writer.write('\r\nWould you like to play a game? ')
    inp = await reader.read(1)
    if inp:
        writer.echo(inp)
        writer.write('\r\nThey say the only way to win '
                     'is to not play at all.\r\n')
        await writer.drain()
    writer.close()

loop = asyncio.get_event_loop()
coro = telnetlib3.create_server('127.0.0.1', 6023, shell=shell)
server = loop.run_until_complete(coro)
loop.run_until_complete(server.wait_closed())

results in

/home/anton/PycharmProjects/XO/venv/PycharmProjects/bin/python /home/anton/.config/JetBrains/PyCharmCE2023.2/scratches/scratch.py 
/home/anton/.config/JetBrains/PyCharmCE2023.2/scratches/scratch.py:13: DeprecationWarning: There is no current event loop
  loop = asyncio.get_event_loop()

Process finished with exit code 0

The internet is full of telnet client examples of usage of this library, but no telnet server.

rugubara avatar Dec 05 '23 15:12 rugubara

I experience the same error. Is there any advice for how to get past it?

e2ibrobbins avatar Jan 30 '24 16:01 e2ibrobbins