-
Notifications
You must be signed in to change notification settings - Fork 0
/
serverSocket.py
executable file
·48 lines (45 loc) · 1.58 KB
/
serverSocket.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
46
47
48
#! /usr/bin/python
import socket
import RPi.GPIO as gpio
import time
listensocket =socket.socket(socket.AF_INET,socket.SOCK_STREAM)
port = 16662
IP = "192.168.88.225"
pin=7
gpio.setmode(gpio.BOARD)
try:
listensocket.bind((IP,port))
listensocket.listen(999)
connectionStatus =False
print("server started "+IP+" on port "+ str(port))
while True:
clientsocket , add= listensocket.accept()
message =clientsocket.recv(8)
print("message is : ", message )
if message == "end":
print("the end")
#clientsocket.clese()
if message != "":
if message =="false":
gpio.setup(pin,gpio.OUT)
connectionStatus=True
elif message=="true":
connectionStatus=False
gpio.setup(pin,gpio.IN)
print(message)
elif message=="getstate":
try:
sendsocket =socket.socket(socket.AF_INET,socket.SOCK_STREAM)
print("sendsocket creat",add[0])
sendsocket.connect((str(add[0]),16662))
print("connect",add[0])
sendsocket.send("connectionStatus:"+str(connectionStatus))
sendsocket.close()
print("send")
except:
print("not send")
except Exception as e :
gpio.cleanup()
print("cleanUP")
print(e)
listensocket.close()