2018-08-07 11:40:02 -04:00
|
|
|
from __future__ import print_function
|
2018-08-07 23:11:11 -04:00
|
|
|
|
2018-08-07 11:40:02 -04:00
|
|
|
from socket import socket, AF_INET, SOCK_DGRAM
|
2018-08-07 23:11:11 -04:00
|
|
|
import time
|
2018-08-07 11:40:02 -04:00
|
|
|
|
|
|
|
listen = ('127.0.0.1', 2237)
|
|
|
|
|
|
|
|
def main():
|
|
|
|
sock = socket(AF_INET, SOCK_DGRAM)
|
|
|
|
print("listening on", ':'.join(map(str, listen)))
|
|
|
|
sock.bind(listen)
|
|
|
|
try:
|
|
|
|
while True:
|
2018-08-07 22:20:28 -04:00
|
|
|
content, addr = sock.recvfrom(65500)
|
2018-08-07 11:40:02 -04:00
|
|
|
print("from:", ":".join(map(str, addr)))
|
2018-08-07 22:41:01 -04:00
|
|
|
|
|
|
|
typ, msg = content.split('|')
|
|
|
|
print("->", typ)
|
|
|
|
print("->", msg)
|
|
|
|
|
|
|
|
if typ == "PING":
|
|
|
|
print("sending pong reply...", end="")
|
2018-08-07 23:11:11 -04:00
|
|
|
sock.sendto("PONG", addr)
|
2018-08-07 22:41:01 -04:00
|
|
|
print("done")
|
2018-08-07 23:11:11 -04:00
|
|
|
|
|
|
|
sock.sendto("SET_GRID|EM73NA99", addr)
|
|
|
|
time.sleep(1)
|
|
|
|
sock.sendto("SET_GRID|EM73NA98", addr)
|
|
|
|
time.sleep(1)
|
|
|
|
sock.sendto("SET_GRID|EM73NA97", addr)
|
|
|
|
|
|
|
|
if typ == "EXIT":
|
|
|
|
break
|
2018-08-07 11:40:02 -04:00
|
|
|
finally:
|
|
|
|
sock.close()
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|