Examples adapted
This commit is contained in:
parent
e92601c6dd
commit
945d728341
@ -1,14 +1,16 @@
|
||||
import sys
|
||||
sys.path.append('../..')
|
||||
|
||||
|
||||
import report
|
||||
import socket_protocol
|
||||
from socket_protocol_server import example_protocol, DID_ASC_TIME
|
||||
import tcp_socket
|
||||
import time
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
report.stdoutLoggingConfigure(log_name_lvl=[('root', 'INFO'), ])
|
||||
c = tcp_socket.tcp_client_stp('127.0.0.1', 17017)
|
||||
sp = socket_protocol.pure_json_protocol(c, channel_name='example_client')
|
||||
sp.send(socket_protocol.SID_READ_REQUEST, 0, None)
|
||||
sp = example_protocol(c, channel_name='example_client')
|
||||
sp.send(socket_protocol.SID_READ_REQUEST, DID_ASC_TIME, None)
|
||||
print('The Client received: %s' % repr(sp.receive(socket_protocol.SID_READ_RESPONSE, 0).get_data()))
|
||||
|
@ -7,17 +7,29 @@ import tcp_socket
|
||||
import time
|
||||
|
||||
|
||||
def time_callback(msg):
|
||||
DID_ASC_TIME = 0
|
||||
|
||||
|
||||
class example_protocol(socket_protocol.pure_json_protocol):
|
||||
def __init__(self, *args, **kwargs):
|
||||
socket_protocol.pure_json_protocol.__init__(self, *args, **kwargs)
|
||||
#
|
||||
self.add_data((socket_protocol.SID_READ_REQUEST, socket_protocol.SID_READ_RESPONSE), DID_ASC_TIME, 'asc_time')
|
||||
#
|
||||
if not self.__comm_inst__.IS_CLIENT:
|
||||
self.register_callback(socket_protocol.SID_READ_REQUEST, 0, self.time_callback)
|
||||
|
||||
def time_callback(self, msg):
|
||||
if msg.get_status() == socket_protocol.STATUS_OKAY:
|
||||
return socket_protocol.STATUS_OKAY, time.asctime()
|
||||
else:
|
||||
return socket_protocol.STATUS_OPERATION_NOT_PERMITTED, None
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
report.stdoutLoggingConfigure(log_name_lvl=[('root', 'INFO'), ])
|
||||
s = tcp_socket.tcp_server_stp('127.0.0.1', 17017)
|
||||
sp = socket_protocol.pure_json_protocol(s, channel_name='example_server')
|
||||
sp.register_callback(socket_protocol.SID_READ_REQUEST, 0, time_callback)
|
||||
sp = example_protocol(s, channel_name='example_server')
|
||||
|
||||
i = 0
|
||||
while not s.is_connected() and i <= 20:
|
||||
|
Loading…
x
Reference in New Issue
Block a user