-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_recver.py
50 lines (39 loc) · 1.18 KB
/
test_recver.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
49
50
import argparse
import socketNumpy
import numpy as np
import signal
parser = argparse.ArgumentParser(description='None')
parser.add_argument('--host', type=str, default='localhost')
parser.add_argument('--port', type=int, default=8090)
args = parser.parse_args()
listenAddress = args.host
listenPort = args.port
serverSocket = None
def handler(signal_received, frame):
# Handle any cleanup here
print('SIGINT or CTRL-C detected. Closing sockets...')
print("Closing socket")
try:
serverSocket.close()
except:pass
print("Exit")
exit(0)
signal.signal(signal.SIGINT, handler)
while True:
try:
serverSocket = socketNumpy.SocketServer(listenAddress, listenPort)
serverSocket.bind_listen_and_accept()
try:
while True:
print("wait for recv...")
d = serverSocket.receive_array()
print(d)
serverSocket.send_numpy_array(np.sum(d)/10000)
except Exception as e:
print(type(e), "Exception occurred. Close connection...")
serverSocket.close()
except Exception as e:
print(type(e))
print(e)
serverSocket.close()
exit(0)