-
Notifications
You must be signed in to change notification settings - Fork 2
/
server_tcp.py
48 lines (41 loc) · 1.17 KB
/
server_tcp.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
# Import the Socket framework.
import socket
# Socket configuration.
HOST, PORT = "localhost", 9999
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
def getPinState(pinNum):
data = "gps::pinState:" + str(pinNum)
try:
sock.connect((HOST, PORT))
sock.sendall(data + "\n")
received = sock.recv(1024)
finally:
sock.close()
def setPinState(pinNum, pinState):
data = "sps::pinNum:" + str(pinNum) + ",pinState:" + pinState
try:
sock.connect((HOST, PORT))
sock.sendall(data + "\n")
received = sock.recv(1024)
finally:
sock.close()
def getTimeDuration(pinNum):
data = "gtd::pinNum:" + str(pinNum)
try:
sock.connect((HOST, PORT))
sock.sendall(data + "\n")
received = sock.recv(1024)
finally:
sock.close()
def setTimeDuration(pinNum, startTime, duration):
data = "std::pinNum:" + str(pinNum) + ",startTime:" + startTime, ",duration:" + duration
try:
sock.connect((HOST, PORT))
sock.sendall(data + "\n")
received = sock.recv(1024)
finally:
sock.close()
if __name__ == "__main__":
setPinState(11, "on")
print "Sent: {}".format(data)
print "Received: {}".format(received)