-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPowMonMan_Server.py
More file actions
50 lines (37 loc) · 1.29 KB
/
Copy pathPowMonMan_Server.py
File metadata and controls
50 lines (37 loc) · 1.29 KB
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
46
47
48
49
50
import sys
import os
import _thread
#from threading import Thread
import socket
def client_thread(conn):
# check pin status
pin_status = os.path.isfile("ON");
if pin_status:
conn.sendall(bytes("true",'utf-8'))
else:
conn.sendall(bytes("false",'utf-8'))
conn.close()
def main():
HOST = '' # Symbolic name, meaning all available interfaces
PORT = 7444 # Arbitrary non-privileged port
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
print('Socket created')
#Bind socket to local host and port
try:
s.bind((HOST, PORT))
except socket.error as msg:
print('Bind failed. Error Code : ' + str(msg[0]) + ' Message ' + msg[1])
sys.exit()
print('Socket bind complete')
#Start listening on socket
s.listen(10)
print('Socket now [el for el in list]stening')
#now keep talking with the client
while True:
#wait to accept a connection - blocking call
conn, addr = s.accept()
print('Connected with ' + addr[0] + ':' + str(addr[1]))
_thread.start_new_thread(client_thread,(conn,))
s.close()
if __name__=="__main__":
main();