Skip to content

Commit

Permalink
Updated README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
ForceFledgling committed Nov 26, 2023
1 parent 6c05c80 commit 177f700
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,62 +23,66 @@ Here is a simple example of using in an asynchronous context.
import asyncio
from asyncio_telnet import Telnet


async def main():
tn = Telnet()
await tn.open('example.com')
await tn.write(b'Vladimir\r\n')
response = await tn.read_until_eof()
await tn.close()
return response

if __name__ == '__main__':
result = asyncio.run(main())
print(result)


# example of successful execution
b'\n***************** User Access Login ********************\r\n\r\nUser:'
# Example of successful execution:
# b'\n***************** User Access Login ********************\r\n\r\nUser:'
```

For synchronous usage, you can use the library in a similar way by simply specifying sync_mode=True.

```python
from asyncio_telnet import Telnet


def main():
# by specifying sync_mode=True, a wrapper for calling
# asynchronous methodssynchronously is activated internally.
tn = Telnet(sync_mode=True)
# now it is possible to directly invoke asynchronous methods through the wrapper
tn.open('example.com')
response = tn.read_until_eof()
tn.close()
return response

if __name__ == '__main__':
result = main()
print(result)


# example of successful execution
b'\n***************** User Access Login ********************\r\n\r\nUser:'
# Example of successful execution:
# b'\n***************** User Access Login ********************\r\n\r\nUser:'
```

Here is a simple example of using in an asynchronous context with a timeout of 5 seconds. By default, the timeout is set to 30 seconds.

```python
import asyncio
from asyncio_telnet import Telnet

async def main():
tn = Telnet(timeout=5)
await tn.open('example.com')
response = await tn.read_until_eof()
return response
try:
await tn.open('example.com')
response = await tn.read_until_eof()
await tn.close()
return response
except ValueError as e:
print(f"Example of a timeout occurrence: {e}")

if __name__ == '__main__':
result = asyncio.run(main())
print(result)
asyncio.run(main())


# example of a timeout occurrence
ValueError: Timeout connecting to example.com:23
# Example response:
# Example of a timeout occurrence: Timeout connecting to example.com:23
```

Feel free to check the [documentation](docs) for more detailed information and examples.
Feel free to check the [documentation](docs) and [examples](examples) for more detailed information.

0 comments on commit 177f700

Please sign in to comment.