This repository has been archived on 2024-07-30. You can view files and clone it, but cannot push or open issues or pull requests.
python-aternos/examples/websocket_example.py

29 lines
519 B
Python
Raw Normal View History

2022-04-06 11:44:14 +04:00
import asyncio
from getpass import getpass
from python_aternos import Client, atwss
user = input('Username: ')
pswd = getpass('Password: ')
aternos = Client.from_credentials(user, pswd)
s = aternos.list_servers()[0]
socket = s.wss()
2022-06-23 15:13:56 +04:00
@socket.wssreceiver(atwss.Streams.console)
2022-04-02 08:58:59 +04:00
async def console(msg):
2022-04-06 11:44:14 +04:00
print('Received:', msg)
2022-06-23 15:13:56 +04:00
2022-04-06 11:44:14 +04:00
async def main():
s.start()
await socket.connect()
2022-05-18 19:35:46 +04:00
await asyncio.create_task(loop())
2022-06-23 15:13:56 +04:00
2022-05-18 19:35:46 +04:00
async def loop():
while True:
await asyncio.sleep(1)
2022-04-06 11:44:14 +04:00
asyncio.run(main())