|
@@ -7,24 +7,36 @@ import tcp_socket
|
7
|
7
|
import time
|
8
|
8
|
|
9
|
9
|
|
10
|
|
-def time_callback(msg):
|
11
|
|
- if msg.get_status() == socket_protocol.STATUS_OKAY:
|
12
|
|
- return socket_protocol.STATUS_OKAY, time.asctime()
|
13
|
|
- else:
|
14
|
|
- return socket_protocol.STATUS_OPERATION_NOT_PERMITTED, None
|
15
|
|
-
|
16
|
|
-
|
17
|
|
-report.stdoutLoggingConfigure(log_name_lvl=[('root', 'INFO'), ])
|
18
|
|
-s = tcp_socket.tcp_server_stp('127.0.0.1', 17017)
|
19
|
|
-sp = socket_protocol.pure_json_protocol(s, channel_name='example_server')
|
20
|
|
-sp.register_callback(socket_protocol.SID_READ_REQUEST, 0, time_callback)
|
21
|
|
-
|
22
|
|
-i = 0
|
23
|
|
-while not s.is_connected() and i <= 20:
|
24
|
|
- i += 1
|
25
|
|
- time.sleep(.1) # wait for a connection
|
26
|
|
-
|
27
|
|
-i = 0
|
28
|
|
-while s.is_connected() and i <= 20:
|
29
|
|
- i += 1
|
30
|
|
- time.sleep(.1) # wait for disconnect
|
|
10
|
+DID_ASC_TIME = 0
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+class example_protocol(socket_protocol.pure_json_protocol):
|
|
14
|
+ def __init__(self, *args, **kwargs):
|
|
15
|
+ socket_protocol.pure_json_protocol.__init__(self, *args, **kwargs)
|
|
16
|
+ #
|
|
17
|
+ self.add_data((socket_protocol.SID_READ_REQUEST, socket_protocol.SID_READ_RESPONSE), DID_ASC_TIME, 'asc_time')
|
|
18
|
+ #
|
|
19
|
+ if not self.__comm_inst__.IS_CLIENT:
|
|
20
|
+ self.register_callback(socket_protocol.SID_READ_REQUEST, 0, self.time_callback)
|
|
21
|
+
|
|
22
|
+ def time_callback(self, msg):
|
|
23
|
+ if msg.get_status() == socket_protocol.STATUS_OKAY:
|
|
24
|
+ return socket_protocol.STATUS_OKAY, time.asctime()
|
|
25
|
+ else:
|
|
26
|
+ return socket_protocol.STATUS_OPERATION_NOT_PERMITTED, None
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+if __name__ == '__main__':
|
|
30
|
+ report.stdoutLoggingConfigure(log_name_lvl=[('root', 'INFO'), ])
|
|
31
|
+ s = tcp_socket.tcp_server_stp('127.0.0.1', 17017)
|
|
32
|
+ sp = example_protocol(s, channel_name='example_server')
|
|
33
|
+
|
|
34
|
+ i = 0
|
|
35
|
+ while not s.is_connected() and i <= 20:
|
|
36
|
+ i += 1
|
|
37
|
+ time.sleep(.1) # wait for a connection
|
|
38
|
+
|
|
39
|
+ i = 0
|
|
40
|
+ while s.is_connected() and i <= 20:
|
|
41
|
+ i += 1
|
|
42
|
+ time.sleep(.1) # wait for disconnect
|