-
Notifications
You must be signed in to change notification settings - Fork 0
/
beebox_sim.py
executable file
·47 lines (37 loc) · 1.24 KB
/
beebox_sim.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
#this is a script to test the BeeBox Server
import socket
HOST = "127.0.0.1" # Standard loopback interface address (localhost)
PORT = 8088 # Port to listen on (non-privileged ports are > 1023)
print(f"Starting server on {HOST}:{PORT}...")
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
try:
s.bind((HOST, PORT))
while(True):
s.listen()
print("Listining...")
conn, addr = s.accept()
with conn:
print(f"Connected by {addr}")
data = conn.recv(1024).decode("utf-8")
if not data:
print("ERROR: No data receved")
print("Command receved: " + data)
#floa = float(23.78)
#print(floa)
#send = pack('!f', floa)
#conn.sendall(send)
#print("Sent data... now closing")
if data[0] == '1':
print("Receved a zero")
conn.sendall(b"OK")
elif data[0] == '2':
print("Receved status request:")
conn.sendall(b"022311")
elif data[0] == '3':
print("Receved dataRequest")
conn.sendall(pack("!d", 123.12))
except:
print("Closing connection...")
s.close()
raise