2022-05-26 12:14:36 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
|
|
import asyncio
|
|
|
|
|
from dataclasses import dataclass
|
|
|
|
|
import datetime
|
|
|
|
|
|
|
|
|
|
import json
|
2022-05-27 22:30:15 +00:00
|
|
|
import random
|
2022-05-26 12:14:36 +00:00
|
|
|
import time
|
|
|
|
|
|
|
|
|
|
import websockets
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@dataclass
|
|
|
|
|
class pixel:
|
|
|
|
|
x: int
|
|
|
|
|
y: int
|
|
|
|
|
color: int
|
|
|
|
|
timestamp: int
|
|
|
|
|
userid: int
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def main():
|
2022-05-27 22:30:15 +00:00
|
|
|
async with websockets.connect("ws://localhost:8080/") as websocket:
|
2022-05-28 13:28:14 +00:00
|
|
|
for _ in range(10):
|
2022-05-27 22:30:15 +00:00
|
|
|
message = pixel(
|
2022-05-28 13:28:14 +00:00
|
|
|
x=random.randint(0, 9),
|
|
|
|
|
y=random.randint(0, 9),
|
2022-05-27 22:30:15 +00:00
|
|
|
color=random.randint(0,15),
|
|
|
|
|
timestamp=int(time.time()),
|
|
|
|
|
userid=1,
|
|
|
|
|
)
|
|
|
|
|
print(message)
|
|
|
|
|
await websocket.send(json.dumps(message.__dict__))
|
|
|
|
|
while True:
|
|
|
|
|
x = await websocket.recv()
|
|
|
|
|
print(x)
|
2022-05-26 12:14:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
asyncio.get_event_loop().run_until_complete(main())
|