-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
31 lines (28 loc) · 819 Bytes
/
server.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
import wAPI
import socket
import threading
socket = socket.socket()
socket.bind(("192.168.1.107",2))
socket.listen()
def connection(client):
global max_min, hours
recv = client.recv(1024).decode()[2:]
if recv == "get_next_hours":
client.send(hours.encode())
elif recv == "get_max_min_temp":
backsend = max_min
client.send(backsend.encode())
print(backsend)
else:
print("unknown command:",recv)
def get_info():
global max_min,hours
while True:
max_min = wAPI.get_max_min_temp()
hours = wAPI.get_next_hours()
info_getter = threading.Thread(target=get_info,args=())
while True:
(client,addr) =socket.accept()
print("connected with: "+str(addr))
thread = threading.Thread(target=connection,args=(client,))
thread.start()