diff --git a/__init__.py b/__init__.py index e08a4ba..7fd1779 100644 --- a/__init__.py +++ b/__init__.py @@ -266,6 +266,18 @@ class pure_json_protocol(object): .. note:: The :const:`channel_name`-exchange will be initiated by the client directly after the the connection is established. * If a channel_name is given at both communication sides and they are different, the client name is taken over and the server will log a warning message. + + **Example:** + + .. literalinclude:: socket_protocol/_examples_/socket_protocol_client.py + + and + + .. literalinclude:: socket_protocol/_examples_/socket_protocol_server.py + + Will result to the following output: + + .. literalinclude:: socket_protocol/_examples_/socket_protocol_client.log """ DEFAULT_CHANNEL_NAME = 'all_others' diff --git a/_docs_/_downloads/37503cb17b21b2c78bb8b07730976f24/unittest.pdf b/_docs_/_downloads/37503cb17b21b2c78bb8b07730976f24/unittest.pdf index 6d98ce9..5adb608 100644 Binary files a/_docs_/_downloads/37503cb17b21b2c78bb8b07730976f24/unittest.pdf and b/_docs_/_downloads/37503cb17b21b2c78bb8b07730976f24/unittest.pdf differ diff --git a/_docs_/index.html b/_docs_/index.html index cc28a21..d9a7b1a 100644 --- a/_docs_/index.html +++ b/_docs_/index.html @@ -471,6 +471,73 @@
Example:
+import sys
+sys.path.append('../..')
+
+import report
+import socket_protocol
+import tcp_socket
+import time
+
+
+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)
+print('The Client received: %s' % repr(sp.receive(socket_protocol.SID_READ_RESPONSE, 0).get_data()))
+
and
+import sys
+sys.path.append('../..')
+
+import report
+import socket_protocol
+import tcp_socket
+import time
+
+
+def time_callback(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
+
+
+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)
+
+i = 0
+while not s.is_connected() and i <= 20:
+ i += 1
+ time.sleep(.1) # wait for a connection
+
+i = 0
+while s.is_connected() and i <= 20:
+ i += 1
+ time.sleep(.1) # wait for disconnect
+
Will result to the following output:
+2021-01-11 17:40:12,803: root.socket_protocol.example_client - INFO - prot-client: Resetting authentification state to AUTH_STATE_UNTRUSTED_CONNECTION
+2021-01-11 17:40:12,803: root.socket_protocol - INFO - prot-client: Initialisation finished.
+2021-01-11 17:40:12,803: root.socket_protocol.example_client - INFO - prot-client: TX -> service: read data request, data_id: 0, status: okay, data: "None"
+2021-01-11 17:40:12,954: root.tcp_socket.example_client - INFO - comm-client: Connection established... (to 127.0.0.1:17017)
+2021-01-11 17:40:12,955: root.socket_protocol.example_client - INFO - prot-client: TX -> service: channel name request, data_id: name, status: okay, data: "'example_client'"
+2021-01-11 17:40:12,956: root.tcp_socket.example_client - INFO - comm-client: TX -> "(74): 7b 22 64 61 74 61 5f 69 64 22 3a 20 30 2c 20 22 73 65 72 76 69 63 65 5f 69 64 22 3a 20 38 2c 20 22 73 74 61 74 75 73 22 3a 20 30 2c 20 22 64 61 74 61 22 3a 20 22 65 78 61 6d 70 6c 65 5f 63 6c 69 65 6e 74 22 7d f5 cd dd e7"
+2021-01-11 17:40:13,004: root.tcp_socket.example_client - INFO - comm-client: TX -> "(63): 7b 22 64 61 74 61 5f 69 64 22 3a 20 30 2c 20 22 73 65 72 76 69 63 65 5f 69 64 22 3a 20 31 30 2c 20 22 73 74 61 74 75 73 22 3a 20 30 2c 20 22 64 61 74 61 22 3a 20 6e 75 6c 6c 7d 45 05 7b b4"
+2021-01-11 17:40:13,057: root.stringtools.stp - INFO - STP: message identified - (62): 7b 22 64 61 74 61 5f 69 64 22 3a 20 30 2c 20 22 73 65 72 76 69 63 65 5f 69 64 22 3a 20 39 2c 20 22 73 74 61 74 75 73 22 3a 20 30 2c 20 22 64 61 74 61 22 3a 20 6e 75 6c 6c 7d 30 59 be 2f
+2021-01-11 17:40:13,058: root.tcp_socket.example_client - INFO - comm-client: RX <- "(62): 7b 22 64 61 74 61 5f 69 64 22 3a 20 30 2c 20 22 73 65 72 76 69 63 65 5f 69 64 22 3a 20 39 2c 20 22 73 74 61 74 75 73 22 3a 20 30 2c 20 22 64 61 74 61 22 3a 20 6e 75 6c 6c 7d 30 59 be 2f"
+2021-01-11 17:40:13,058: root.socket_protocol.example_client - INFO - prot-client: RX <- service: channel name response, data_id: name, status: okay, data: "None"
+2021-01-11 17:40:13,109: root.stringtools.stp - INFO - STP: message identified - (85): 7b 22 64 61 74 61 5f 69 64 22 3a 20 30 2c 20 22 73 65 72 76 69 63 65 5f 69 64 22 3a 20 31 31 2c 20 22 73 74 61 74 75 73 22 3a 20 30 2c 20 22 64 61 74 61 22 3a 20 22 4d 6f 6e 20 4a 61 6e 20 31 31 20 31 37 3a 34 30 3a 31 33 20 32 30 32 31 22 7d dd 78 8e ae
+2021-01-11 17:40:13,109: root.tcp_socket.example_client - INFO - comm-client: RX <- "(85): 7b 22 64 61 74 61 5f 69 64 22 3a 20 30 2c 20 22 73 65 72 76 69 63 65 5f 69 64 22 3a 20 31 31 2c 20 22 73 74 61 74 75 73 22 3a 20 30 2c 20 22 64 61 74 61 22 3a 20 22 4d 6f 6e 20 4a 61 6e 20 31 31 20 31 37 3a 34 30 3a 31 33 20 32 30 32 31 22 7d dd 78 8e ae"
+2021-01-11 17:40:13,110: root.socket_protocol.example_client - INFO - prot-client: RX <- service: read data response, data_id: 0, status: okay, data: "'Mon Jan 11 17:40:13 2021'"
+The Client received: 'Mon Jan 11 17:40:13 2021'
+
add_data
(service_id, data_id, name)ΒΆ