-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathws_server_p1.py
45 lines (38 loc) · 1.22 KB
/
ws_server_p1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import asyncio
import websockets
import pickle
import json
import socket
import threading
from threading import Thread
import _thread
import time
HOST = '192.168.43.235' # The socket server's hostname or IP address
PORT = 54087 # The port used by the server
Gateway_IP = '192.168.43.8' # for websocket server
data = ''
connect = 0
data = "{\"right\":0,\"left\":0,\"up\":0,\"down\":0,\"hit\":0}"
async def hello(websocket, path):
'''print('echo')
async for message in websocket:
print(message,'received from client')
greeting = f"Hello {message}!"
await websocket.send(greeting)
print(f"> {greeting}")
'''
while True:
data = s.recv(1024).decode('utf-8')
print(data)
time.sleep(0.0001)
await websocket.send(data)
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.bind((HOST, PORT))
try:
start_server = websockets.serve(hello, "127.0.0.1", 8866, ping_interval=None)
asyncio.get_event_loop().run_until_complete(start_server)
asyncio.get_event_loop().run_forever()
print("GG")
data = "{right:0,left:0,up:0,down:0,hit:0}"
except KeyboardInterrupt:
s.close()