Ver código fonte

Example added to Documentation

master
Dirk Alders 4 anos atrás
pai
commit
e92601c6dd

+ 12
- 0
__init__.py Ver arquivo

@@ -266,6 +266,18 @@ class pure_json_protocol(object):
266 266
     .. note::  The :const:`channel_name`-exchange will be initiated by the client directly after the the connection is established.
267 267
 
268 268
         * 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.
269
+
270
+    **Example:**
271
+
272
+    .. literalinclude:: socket_protocol/_examples_/socket_protocol_client.py
273
+
274
+    and
275
+
276
+    .. literalinclude:: socket_protocol/_examples_/socket_protocol_server.py
277
+
278
+    Will result to the following output:
279
+
280
+    .. literalinclude:: socket_protocol/_examples_/socket_protocol_client.log
269 281
     """
270 282
     DEFAULT_CHANNEL_NAME = 'all_others'
271 283
 

BIN
_docs_/_downloads/37503cb17b21b2c78bb8b07730976f24/unittest.pdf Ver arquivo


+ 67
- 0
_docs_/index.html Ver arquivo

@@ -471,6 +471,73 @@
471 471
 <li>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.</li>
472 472
 </ul>
473 473
 </div>
474
+<p><strong>Example:</strong></p>
475
+<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">sys</span>
476
+<span class="n">sys</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;../..&#39;</span><span class="p">)</span>
477
+
478
+<span class="kn">import</span> <span class="nn">report</span>
479
+<span class="kn">import</span> <span class="nn">socket_protocol</span>
480
+<span class="kn">import</span> <span class="nn">tcp_socket</span>
481
+<span class="kn">import</span> <span class="nn">time</span>
482
+
483
+
484
+<span class="n">report</span><span class="o">.</span><span class="n">stdoutLoggingConfigure</span><span class="p">(</span><span class="n">log_name_lvl</span><span class="o">=</span><span class="p">[(</span><span class="s1">&#39;root&#39;</span><span class="p">,</span> <span class="s1">&#39;INFO&#39;</span><span class="p">),</span> <span class="p">])</span>
485
+<span class="n">c</span> <span class="o">=</span> <span class="n">tcp_socket</span><span class="o">.</span><span class="n">tcp_client_stp</span><span class="p">(</span><span class="s1">&#39;127.0.0.1&#39;</span><span class="p">,</span> <span class="mi">17017</span><span class="p">)</span>
486
+<span class="n">sp</span> <span class="o">=</span> <span class="n">socket_protocol</span><span class="o">.</span><span class="n">pure_json_protocol</span><span class="p">(</span><span class="n">c</span><span class="p">,</span> <span class="n">channel_name</span><span class="o">=</span><span class="s1">&#39;example_client&#39;</span><span class="p">)</span>
487
+<span class="n">sp</span><span class="o">.</span><span class="n">send</span><span class="p">(</span><span class="n">socket_protocol</span><span class="o">.</span><span class="n">SID_READ_REQUEST</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
488
+<span class="nb">print</span><span class="p">(</span><span class="s1">&#39;The Client received: </span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="nb">repr</span><span class="p">(</span><span class="n">sp</span><span class="o">.</span><span class="n">receive</span><span class="p">(</span><span class="n">socket_protocol</span><span class="o">.</span><span class="n">SID_READ_RESPONSE</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span><span class="o">.</span><span class="n">get_data</span><span class="p">()))</span>
489
+</pre></div>
490
+</div>
491
+<p>and</p>
492
+<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">sys</span>
493
+<span class="n">sys</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;../..&#39;</span><span class="p">)</span>
494
+
495
+<span class="kn">import</span> <span class="nn">report</span>
496
+<span class="kn">import</span> <span class="nn">socket_protocol</span>
497
+<span class="kn">import</span> <span class="nn">tcp_socket</span>
498
+<span class="kn">import</span> <span class="nn">time</span>
499
+
500
+
501
+<span class="k">def</span> <span class="nf">time_callback</span><span class="p">(</span><span class="n">msg</span><span class="p">):</span>
502
+    <span class="k">if</span> <span class="n">msg</span><span class="o">.</span><span class="n">get_status</span><span class="p">()</span> <span class="o">==</span> <span class="n">socket_protocol</span><span class="o">.</span><span class="n">STATUS_OKAY</span><span class="p">:</span>
503
+        <span class="k">return</span> <span class="n">socket_protocol</span><span class="o">.</span><span class="n">STATUS_OKAY</span><span class="p">,</span> <span class="n">time</span><span class="o">.</span><span class="n">asctime</span><span class="p">()</span>
504
+    <span class="k">else</span><span class="p">:</span>
505
+        <span class="k">return</span> <span class="n">socket_protocol</span><span class="o">.</span><span class="n">STATUS_OPERATION_NOT_PERMITTED</span><span class="p">,</span> <span class="kc">None</span>
506
+
507
+
508
+<span class="n">report</span><span class="o">.</span><span class="n">stdoutLoggingConfigure</span><span class="p">(</span><span class="n">log_name_lvl</span><span class="o">=</span><span class="p">[(</span><span class="s1">&#39;root&#39;</span><span class="p">,</span> <span class="s1">&#39;INFO&#39;</span><span class="p">),</span> <span class="p">])</span>
509
+<span class="n">s</span> <span class="o">=</span> <span class="n">tcp_socket</span><span class="o">.</span><span class="n">tcp_server_stp</span><span class="p">(</span><span class="s1">&#39;127.0.0.1&#39;</span><span class="p">,</span> <span class="mi">17017</span><span class="p">)</span>
510
+<span class="n">sp</span> <span class="o">=</span> <span class="n">socket_protocol</span><span class="o">.</span><span class="n">pure_json_protocol</span><span class="p">(</span><span class="n">s</span><span class="p">,</span> <span class="n">channel_name</span><span class="o">=</span><span class="s1">&#39;example_server&#39;</span><span class="p">)</span>
511
+<span class="n">sp</span><span class="o">.</span><span class="n">register_callback</span><span class="p">(</span><span class="n">socket_protocol</span><span class="o">.</span><span class="n">SID_READ_REQUEST</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">time_callback</span><span class="p">)</span>
512
+
513
+<span class="n">i</span> <span class="o">=</span> <span class="mi">0</span>
514
+<span class="k">while</span> <span class="ow">not</span> <span class="n">s</span><span class="o">.</span><span class="n">is_connected</span><span class="p">()</span> <span class="ow">and</span> <span class="n">i</span> <span class="o">&lt;=</span> <span class="mi">20</span><span class="p">:</span>
515
+    <span class="n">i</span> <span class="o">+=</span> <span class="mi">1</span>
516
+    <span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="o">.</span><span class="mi">1</span><span class="p">)</span>  <span class="c1"># wait for a connection</span>
517
+
518
+<span class="n">i</span> <span class="o">=</span> <span class="mi">0</span>
519
+<span class="k">while</span> <span class="n">s</span><span class="o">.</span><span class="n">is_connected</span><span class="p">()</span> <span class="ow">and</span> <span class="n">i</span> <span class="o">&lt;=</span> <span class="mi">20</span><span class="p">:</span>
520
+    <span class="n">i</span> <span class="o">+=</span> <span class="mi">1</span>
521
+    <span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="o">.</span><span class="mi">1</span><span class="p">)</span>  <span class="c1"># wait for disconnect</span>
522
+</pre></div>
523
+</div>
524
+<p>Will result to the following output:</p>
525
+<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="mi">2021</span><span class="o">-</span><span class="mi">01</span><span class="o">-</span><span class="mi">11</span> <span class="mi">17</span><span class="p">:</span><span class="mi">40</span><span class="p">:</span><span class="mi">12</span><span class="p">,</span><span class="mi">803</span><span class="p">:</span> <span class="n">root</span><span class="o">.</span><span class="n">socket_protocol</span><span class="o">.</span><span class="n">example_client</span> <span class="o">-</span> <span class="n">INFO</span> <span class="o">-</span> <span class="n">prot</span><span class="o">-</span><span class="n">client</span><span class="p">:</span> <span class="n">Resetting</span> <span class="n">authentification</span> <span class="n">state</span> <span class="n">to</span> <span class="n">AUTH_STATE_UNTRUSTED_CONNECTION</span>
526
+<span class="mi">2021</span><span class="o">-</span><span class="mi">01</span><span class="o">-</span><span class="mi">11</span> <span class="mi">17</span><span class="p">:</span><span class="mi">40</span><span class="p">:</span><span class="mi">12</span><span class="p">,</span><span class="mi">803</span><span class="p">:</span> <span class="n">root</span><span class="o">.</span><span class="n">socket_protocol</span> <span class="o">-</span> <span class="n">INFO</span> <span class="o">-</span> <span class="n">prot</span><span class="o">-</span><span class="n">client</span><span class="p">:</span> <span class="n">Initialisation</span> <span class="n">finished</span><span class="o">.</span>
527
+<span class="mi">2021</span><span class="o">-</span><span class="mi">01</span><span class="o">-</span><span class="mi">11</span> <span class="mi">17</span><span class="p">:</span><span class="mi">40</span><span class="p">:</span><span class="mi">12</span><span class="p">,</span><span class="mi">803</span><span class="p">:</span> <span class="n">root</span><span class="o">.</span><span class="n">socket_protocol</span><span class="o">.</span><span class="n">example_client</span> <span class="o">-</span> <span class="n">INFO</span> <span class="o">-</span> <span class="n">prot</span><span class="o">-</span><span class="n">client</span><span class="p">:</span> <span class="n">TX</span> <span class="o">-&gt;</span> <span class="n">service</span><span class="p">:</span> <span class="n">read</span> <span class="n">data</span> <span class="n">request</span><span class="p">,</span> <span class="n">data_id</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span> <span class="n">status</span><span class="p">:</span> <span class="n">okay</span><span class="p">,</span> <span class="n">data</span><span class="p">:</span> <span class="s2">&quot;None&quot;</span>
528
+<span class="mi">2021</span><span class="o">-</span><span class="mi">01</span><span class="o">-</span><span class="mi">11</span> <span class="mi">17</span><span class="p">:</span><span class="mi">40</span><span class="p">:</span><span class="mi">12</span><span class="p">,</span><span class="mi">954</span><span class="p">:</span> <span class="n">root</span><span class="o">.</span><span class="n">tcp_socket</span><span class="o">.</span><span class="n">example_client</span> <span class="o">-</span> <span class="n">INFO</span> <span class="o">-</span> <span class="n">comm</span><span class="o">-</span><span class="n">client</span><span class="p">:</span> <span class="n">Connection</span> <span class="n">established</span><span class="o">...</span> <span class="p">(</span><span class="n">to</span> <span class="mf">127.0</span><span class="o">.</span><span class="mf">0.1</span><span class="p">:</span><span class="mi">17017</span><span class="p">)</span>
529
+<span class="mi">2021</span><span class="o">-</span><span class="mi">01</span><span class="o">-</span><span class="mi">11</span> <span class="mi">17</span><span class="p">:</span><span class="mi">40</span><span class="p">:</span><span class="mi">12</span><span class="p">,</span><span class="mi">955</span><span class="p">:</span> <span class="n">root</span><span class="o">.</span><span class="n">socket_protocol</span><span class="o">.</span><span class="n">example_client</span> <span class="o">-</span> <span class="n">INFO</span> <span class="o">-</span> <span class="n">prot</span><span class="o">-</span><span class="n">client</span><span class="p">:</span> <span class="n">TX</span> <span class="o">-&gt;</span> <span class="n">service</span><span class="p">:</span> <span class="n">channel</span> <span class="n">name</span> <span class="n">request</span><span class="p">,</span> <span class="n">data_id</span><span class="p">:</span> <span class="n">name</span><span class="p">,</span> <span class="n">status</span><span class="p">:</span> <span class="n">okay</span><span class="p">,</span> <span class="n">data</span><span class="p">:</span> <span class="s2">&quot;&#39;example_client&#39;&quot;</span>
530
+<span class="mi">2021</span><span class="o">-</span><span class="mi">01</span><span class="o">-</span><span class="mi">11</span> <span class="mi">17</span><span class="p">:</span><span class="mi">40</span><span class="p">:</span><span class="mi">12</span><span class="p">,</span><span class="mi">956</span><span class="p">:</span> <span class="n">root</span><span class="o">.</span><span class="n">tcp_socket</span><span class="o">.</span><span class="n">example_client</span> <span class="o">-</span> <span class="n">INFO</span> <span class="o">-</span> <span class="n">comm</span><span class="o">-</span><span class="n">client</span><span class="p">:</span> <span class="n">TX</span> <span class="o">-&gt;</span> <span class="s2">&quot;(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&quot;</span>
531
+<span class="mi">2021</span><span class="o">-</span><span class="mi">01</span><span class="o">-</span><span class="mi">11</span> <span class="mi">17</span><span class="p">:</span><span class="mi">40</span><span class="p">:</span><span class="mi">13</span><span class="p">,</span><span class="mi">004</span><span class="p">:</span> <span class="n">root</span><span class="o">.</span><span class="n">tcp_socket</span><span class="o">.</span><span class="n">example_client</span> <span class="o">-</span> <span class="n">INFO</span> <span class="o">-</span> <span class="n">comm</span><span class="o">-</span><span class="n">client</span><span class="p">:</span> <span class="n">TX</span> <span class="o">-&gt;</span> <span class="s2">&quot;(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&quot;</span>
532
+<span class="mi">2021</span><span class="o">-</span><span class="mi">01</span><span class="o">-</span><span class="mi">11</span> <span class="mi">17</span><span class="p">:</span><span class="mi">40</span><span class="p">:</span><span class="mi">13</span><span class="p">,</span><span class="mi">057</span><span class="p">:</span> <span class="n">root</span><span class="o">.</span><span class="n">stringtools</span><span class="o">.</span><span class="n">stp</span> <span class="o">-</span> <span class="n">INFO</span> <span class="o">-</span> <span class="n">STP</span><span class="p">:</span> <span class="n">message</span> <span class="n">identified</span> <span class="o">-</span> <span class="p">(</span><span class="mi">62</span><span class="p">):</span> <span class="mi">7</span><span class="n">b</span> <span class="mi">22</span> <span class="mi">64</span> <span class="mi">61</span> <span class="mi">74</span> <span class="mi">61</span> <span class="mi">5</span><span class="n">f</span> <span class="mi">69</span> <span class="mi">64</span> <span class="mi">22</span> <span class="mi">3</span><span class="n">a</span> <span class="mi">20</span> <span class="mi">30</span> <span class="mi">2</span><span class="n">c</span> <span class="mi">20</span> <span class="mi">22</span> <span class="mi">73</span> <span class="mi">65</span> <span class="mi">72</span> <span class="mi">76</span> <span class="mi">69</span> <span class="mi">63</span> <span class="mi">65</span> <span class="mi">5</span><span class="n">f</span> <span class="mi">69</span> <span class="mi">64</span> <span class="mi">22</span> <span class="mi">3</span><span class="n">a</span> <span class="mi">20</span> <span class="mi">39</span> <span class="mi">2</span><span class="n">c</span> <span class="mi">20</span> <span class="mi">22</span> <span class="mi">73</span> <span class="mi">74</span> <span class="mi">61</span> <span class="mi">74</span> <span class="mi">75</span> <span class="mi">73</span> <span class="mi">22</span> <span class="mi">3</span><span class="n">a</span> <span class="mi">20</span> <span class="mi">30</span> <span class="mi">2</span><span class="n">c</span> <span class="mi">20</span> <span class="mi">22</span> <span class="mi">64</span> <span class="mi">61</span> <span class="mi">74</span> <span class="mi">61</span> <span class="mi">22</span> <span class="mi">3</span><span class="n">a</span> <span class="mi">20</span> <span class="mi">6</span><span class="n">e</span> <span class="mi">75</span> <span class="mi">6</span><span class="n">c</span> <span class="mi">6</span><span class="n">c</span> <span class="mi">7</span><span class="n">d</span> <span class="mi">30</span> <span class="mi">59</span> <span class="n">be</span> <span class="mi">2</span><span class="n">f</span>
533
+<span class="mi">2021</span><span class="o">-</span><span class="mi">01</span><span class="o">-</span><span class="mi">11</span> <span class="mi">17</span><span class="p">:</span><span class="mi">40</span><span class="p">:</span><span class="mi">13</span><span class="p">,</span><span class="mi">058</span><span class="p">:</span> <span class="n">root</span><span class="o">.</span><span class="n">tcp_socket</span><span class="o">.</span><span class="n">example_client</span> <span class="o">-</span> <span class="n">INFO</span> <span class="o">-</span> <span class="n">comm</span><span class="o">-</span><span class="n">client</span><span class="p">:</span> <span class="n">RX</span>  <span class="o">&lt;-</span> <span class="s2">&quot;(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&quot;</span>
534
+<span class="mi">2021</span><span class="o">-</span><span class="mi">01</span><span class="o">-</span><span class="mi">11</span> <span class="mi">17</span><span class="p">:</span><span class="mi">40</span><span class="p">:</span><span class="mi">13</span><span class="p">,</span><span class="mi">058</span><span class="p">:</span> <span class="n">root</span><span class="o">.</span><span class="n">socket_protocol</span><span class="o">.</span><span class="n">example_client</span> <span class="o">-</span> <span class="n">INFO</span> <span class="o">-</span> <span class="n">prot</span><span class="o">-</span><span class="n">client</span><span class="p">:</span> <span class="n">RX</span> <span class="o">&lt;-</span> <span class="n">service</span><span class="p">:</span> <span class="n">channel</span> <span class="n">name</span> <span class="n">response</span><span class="p">,</span> <span class="n">data_id</span><span class="p">:</span> <span class="n">name</span><span class="p">,</span> <span class="n">status</span><span class="p">:</span> <span class="n">okay</span><span class="p">,</span> <span class="n">data</span><span class="p">:</span> <span class="s2">&quot;None&quot;</span>
535
+<span class="mi">2021</span><span class="o">-</span><span class="mi">01</span><span class="o">-</span><span class="mi">11</span> <span class="mi">17</span><span class="p">:</span><span class="mi">40</span><span class="p">:</span><span class="mi">13</span><span class="p">,</span><span class="mi">109</span><span class="p">:</span> <span class="n">root</span><span class="o">.</span><span class="n">stringtools</span><span class="o">.</span><span class="n">stp</span> <span class="o">-</span> <span class="n">INFO</span> <span class="o">-</span> <span class="n">STP</span><span class="p">:</span> <span class="n">message</span> <span class="n">identified</span> <span class="o">-</span> <span class="p">(</span><span class="mi">85</span><span class="p">):</span> <span class="mi">7</span><span class="n">b</span> <span class="mi">22</span> <span class="mi">64</span> <span class="mi">61</span> <span class="mi">74</span> <span class="mi">61</span> <span class="mi">5</span><span class="n">f</span> <span class="mi">69</span> <span class="mi">64</span> <span class="mi">22</span> <span class="mi">3</span><span class="n">a</span> <span class="mi">20</span> <span class="mi">30</span> <span class="mi">2</span><span class="n">c</span> <span class="mi">20</span> <span class="mi">22</span> <span class="mi">73</span> <span class="mi">65</span> <span class="mi">72</span> <span class="mi">76</span> <span class="mi">69</span> <span class="mi">63</span> <span class="mi">65</span> <span class="mi">5</span><span class="n">f</span> <span class="mi">69</span> <span class="mi">64</span> <span class="mi">22</span> <span class="mi">3</span><span class="n">a</span> <span class="mi">20</span> <span class="mi">31</span> <span class="mi">31</span> <span class="mi">2</span><span class="n">c</span> <span class="mi">20</span> <span class="mi">22</span> <span class="mi">73</span> <span class="mi">74</span> <span class="mi">61</span> <span class="mi">74</span> <span class="mi">75</span> <span class="mi">73</span> <span class="mi">22</span> <span class="mi">3</span><span class="n">a</span> <span class="mi">20</span> <span class="mi">30</span> <span class="mi">2</span><span class="n">c</span> <span class="mi">20</span> <span class="mi">22</span> <span class="mi">64</span> <span class="mi">61</span> <span class="mi">74</span> <span class="mi">61</span> <span class="mi">22</span> <span class="mi">3</span><span class="n">a</span> <span class="mi">20</span> <span class="mi">22</span> <span class="mi">4</span><span class="n">d</span> <span class="mi">6</span><span class="n">f</span> <span class="mi">6</span><span class="n">e</span> <span class="mi">20</span> <span class="mi">4</span><span class="n">a</span> <span class="mi">61</span> <span class="mi">6</span><span class="n">e</span> <span class="mi">20</span> <span class="mi">31</span> <span class="mi">31</span> <span class="mi">20</span> <span class="mi">31</span> <span class="mi">37</span> <span class="mi">3</span><span class="n">a</span> <span class="mi">34</span> <span class="mi">30</span> <span class="mi">3</span><span class="n">a</span> <span class="mi">31</span> <span class="mi">33</span> <span class="mi">20</span> <span class="mi">32</span> <span class="mi">30</span> <span class="mi">32</span> <span class="mi">31</span> <span class="mi">22</span> <span class="mi">7</span><span class="n">d</span> <span class="n">dd</span> <span class="mi">78</span> <span class="mi">8</span><span class="n">e</span> <span class="n">ae</span>
536
+<span class="mi">2021</span><span class="o">-</span><span class="mi">01</span><span class="o">-</span><span class="mi">11</span> <span class="mi">17</span><span class="p">:</span><span class="mi">40</span><span class="p">:</span><span class="mi">13</span><span class="p">,</span><span class="mi">109</span><span class="p">:</span> <span class="n">root</span><span class="o">.</span><span class="n">tcp_socket</span><span class="o">.</span><span class="n">example_client</span> <span class="o">-</span> <span class="n">INFO</span> <span class="o">-</span> <span class="n">comm</span><span class="o">-</span><span class="n">client</span><span class="p">:</span> <span class="n">RX</span>  <span class="o">&lt;-</span> <span class="s2">&quot;(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&quot;</span>
537
+<span class="mi">2021</span><span class="o">-</span><span class="mi">01</span><span class="o">-</span><span class="mi">11</span> <span class="mi">17</span><span class="p">:</span><span class="mi">40</span><span class="p">:</span><span class="mi">13</span><span class="p">,</span><span class="mi">110</span><span class="p">:</span> <span class="n">root</span><span class="o">.</span><span class="n">socket_protocol</span><span class="o">.</span><span class="n">example_client</span> <span class="o">-</span> <span class="n">INFO</span> <span class="o">-</span> <span class="n">prot</span><span class="o">-</span><span class="n">client</span><span class="p">:</span> <span class="n">RX</span> <span class="o">&lt;-</span> <span class="n">service</span><span class="p">:</span> <span class="n">read</span> <span class="n">data</span> <span class="n">response</span><span class="p">,</span> <span class="n">data_id</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span> <span class="n">status</span><span class="p">:</span> <span class="n">okay</span><span class="p">,</span> <span class="n">data</span><span class="p">:</span> <span class="s2">&quot;&#39;Mon Jan 11 17:40:13 2021&#39;&quot;</span>
538
+<span class="n">The</span> <span class="n">Client</span> <span class="n">received</span><span class="p">:</span> <span class="s1">&#39;Mon Jan 11 17:40:13 2021&#39;</span>
539
+</pre></div>
540
+</div>
474 541
 <dl class="method">
475 542
 <dt id="socket_protocol.pure_json_protocol.add_data">
476 543
 <code class="descname">add_data</code><span class="sig-paren">(</span><em>service_id</em>, <em>data_id</em>, <em>name</em><span class="sig-paren">)</span><a class="headerlink" href="#socket_protocol.pure_json_protocol.add_data" title="Permalink to this definition">¶</a></dt>

+ 1
- 1
_docs_/searchindex.js
Diferenças do arquivo suprimidas por serem muito extensas
Ver arquivo


+ 5
- 1
_examples_/Makefile Ver arquivo

@@ -4,7 +4,11 @@ LOGFILES = ${EXAMPLES:.py=.log}
4 4
 .PHONY: all
5 5
 all: $(LOGFILES)
6 6
 
7
-%.log: %.py
7
+%server.log: %server.py
8
+	@echo -n
9
+
10
+%client.log: %client.py
11
+	python3 $(subst client,server,$<) 1> /dev/null&
8 12
 	python3 $< > $@
9 13
 
10 14
 clean:

+ 14
- 0
_examples_/socket_protocol_client.py Ver arquivo

@@ -0,0 +1,14 @@
1
+import sys
2
+sys.path.append('../..')
3
+
4
+import report
5
+import socket_protocol
6
+import tcp_socket
7
+import time
8
+
9
+
10
+report.stdoutLoggingConfigure(log_name_lvl=[('root', 'INFO'), ])
11
+c = tcp_socket.tcp_client_stp('127.0.0.1', 17017)
12
+sp = socket_protocol.pure_json_protocol(c, channel_name='example_client')
13
+sp.send(socket_protocol.SID_READ_REQUEST, 0, None)
14
+print('The Client received: %s' % repr(sp.receive(socket_protocol.SID_READ_RESPONSE, 0).get_data()))

+ 30
- 0
_examples_/socket_protocol_server.py Ver arquivo

@@ -0,0 +1,30 @@
1
+import sys
2
+sys.path.append('../..')
3
+
4
+import report
5
+import socket_protocol
6
+import tcp_socket
7
+import time
8
+
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

Carregando…
Cancelar
Salvar