jquast / telnetlib3

Python Telnet server and client Protocol library using asyncio
Other
147 stars 32 forks source link

Telnet server example doesn't work #81

Open rugubara opened 11 months ago

rugubara commented 11 months ago

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.

e2ibrobbins commented 9 months ago

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