-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsocket_test_s.py
More file actions
45 lines (37 loc) · 825 Bytes
/
socket_test_s.py
File metadata and controls
45 lines (37 loc) · 825 Bytes
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
#!/usr/bin/env python
import socket
import sockethandler
import serialization
from time import sleep
def callback(uid, object):
if object:
print("Callback OK.")
print(object.kp)
print(object.ki)
print(object.kd)
else:
print("No object :(")
handler = sockethandler.SocketHandlerReceiver()
serv_sock = socket.socket()
serv_sock.bind(('127.0.0.1', 6701))
serv_sock.listen(1)
s1, addr = serv_sock.accept()
s1.setblocking(0)
serv_sock.listen(1)
s2, addr = serv_sock.accept()
s2.setblocking(0)
handler.add_socket(s1)
handler.add_socket(s2)
handler.add_msg_type(
serialization.PIDConfig.hash,
serialization.PIDConfig,
callback
)
try:
while True:
handler.handle()
sleep(0.005)
except:
print("Interrupted.")
s1.close()
s2.close()