Configured to add network delay and check message IDs
This commit is contained in:
parent
d9d3e46d44
commit
a3042432f2
@ -35,7 +35,12 @@ class TestClient:
|
||||
async def receive(self) -> None:
|
||||
while (self.connected):
|
||||
response: str = await self.connection.recv()
|
||||
data: dict = json.loads(response)
|
||||
print(f"Received: {response}")
|
||||
|
||||
print(f"CURRENT MESSAGE ID: {self.msgId} - RECEIVED MESSAGE ID: {data["ID"]}")
|
||||
if (data["ID"] != self.msgId - 1):
|
||||
print("MESSAGE DISCARDED\n")
|
||||
else:
|
||||
print("MESSAGE UP TO DATE. ACCEPTED\n")
|
||||
if __name__ == "__main__":
|
||||
client = TestClient()
|
||||
|
@ -1,5 +1,5 @@
|
||||
from websockets import *
|
||||
import asyncio, json, signal, sys
|
||||
import asyncio, json, signal, sys, time, random
|
||||
|
||||
class WebSocketServer:
|
||||
server: Server = None
|
||||
@ -22,6 +22,7 @@ class WebSocketServer:
|
||||
raw: str = await connection.recv()
|
||||
message = json.loads(raw)
|
||||
print(f"Received: {message["message"]} width id {message["ID"]}")
|
||||
time.sleep(random.randrange(1, 10) / 10)
|
||||
response = {"ID": message["ID"], "message": f"received: {message["message"]}"}
|
||||
await connection.send(json.dumps(response))
|
||||
print("Server replied")
|
||||
|
Loading…
x
Reference in New Issue
Block a user