Skip to content

Commit

Permalink
comments: test-server
Browse files Browse the repository at this point in the history
  • Loading branch information
lideming committed May 19, 2021
1 parent 014dae9 commit e80fbd2
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions test-server/test-server.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""
This is a test server for testing the performance of the rear video rendering.
"""

import json
import websockets
import asyncio
Expand All @@ -6,18 +10,30 @@


async def client_handler(client: websockets.WebSocketServerProtocol, path: str):
"""
The asyncio routine for each established client.
There should be excatly one client though.
"""

print('client connected', client.remote_address)
try:
# Pre-generate the fake image for lower overhead
img = np.empty((720, 1280, 3), np.uint8)
# ret, buf = cv2.imencode('*.bmp', img)
buf = img.tobytes("C")

while True:
# Wait for the "request frame" message from the client
await client.recv();

# Send the image "header"
await client.send(json.dumps({'image': {'w': img.shape[1], 'h': img.shape[0]}}))
# img = img.tobytes("C")
# print(len(buf))

#
await client.send(buf)

# # The sleeping was used to control the framerate before we
# # changed the "request frame" protocol.
# await asyncio.sleep(0.03)

finally:
Expand All @@ -26,10 +42,11 @@ async def client_handler(client: websockets.WebSocketServerProtocol, path: str):


async def main():
# Be sure to disable transport compression of websockets
server = await websockets.serve(client_handler, '127.0.0.1', 8765, compression=None)
print('test server started listening...')
await server.wait_closed()


if __name__ == '__main__':
asyncio.run(main())
asyncio.run(main())

0 comments on commit e80fbd2

Please sign in to comment.