r_place/python/clients.py

38 lines
649 B
Python
Raw Normal View History

2022-05-26 12:14:36 +00:00
#!/usr/bin/env python
import asyncio
from dataclasses import dataclass
import datetime
import json
import time
import websockets
@dataclass
class pixel:
x: int
y: int
color: int
timestamp: int
userid: int
async def main():
message = pixel(
2022-05-27 14:12:27 +00:00
x=11,
y=0,
color=15,
2022-05-26 12:14:36 +00:00
timestamp=int(time.time()),
2022-05-27 14:12:27 +00:00
userid=1,
2022-05-26 12:14:36 +00:00
)
2022-05-27 16:00:19 +00:00
async with websockets.connect("ws://localhost:8080/set") as websocket:
2022-05-26 12:14:36 +00:00
print(message)
await websocket.send(json.dumps(message.__dict__))
await websocket.recv()
if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(main())