Arguments in wssreceiver, 1.0.5
This commit is contained in:
parent
b02e833702
commit
cc3099123e
4 changed files with 47 additions and 7 deletions
25
examples/websocket_args_example.py
Normal file
25
examples/websocket_args_example.py
Normal file
|
@ -0,0 +1,25 @@
|
|||
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()
|
||||
|
||||
@socket.wssreceiver(atwss.Streams.console, 'Server 1')
|
||||
async def console(msg, args):
|
||||
print(args[0], 'received', msg)
|
||||
|
||||
async def main():
|
||||
s.start()
|
||||
await socket.connect()
|
||||
await asyncio.create_task(loop())
|
||||
|
||||
async def loop():
|
||||
while True:
|
||||
await asyncio.sleep(1)
|
||||
|
||||
asyncio.run(main())
|
|
@ -16,5 +16,10 @@ async def console(msg):
|
|||
async def main():
|
||||
s.start()
|
||||
await socket.connect()
|
||||
await asyncio.create_task(loop())
|
||||
|
||||
async def loop():
|
||||
while True:
|
||||
await asyncio.sleep(1)
|
||||
|
||||
asyncio.run(main())
|
||||
|
|
Reference in a new issue