1, distributed description
This module contains some processing methods of communication between server and client, including encapsulation of sending data, encapsulation of protocol header, subcontracting of TCP communication and processing of sticky packets.
2. Structure Analysis
<ignore_js_op>
Liberatefactory, the Protocol factory, the nature of all connections, the visualization of the service-side communication with the client, which contains three parts:
1) Liberateprotocol, the Communication protocol class, the connection establishment, the disconnection operation, sends the data and so on it to control
2) Datapackprotoc, the definition of packet protocol, all data parsing must abide by its custom rules
3) ConnectionManager, Connection Manager, all connections are under his command, you can find the connection in it, to operate
Connection, a Connection object with the client, through which he can communicate with the client, actively disconnect, actively push messages and so on.
3. Examples of Use
1) test_netconnect_server.py
<ignore_js_op>
2) test_netconnect_client.py
<ignore_js_op>
3) The above is the server (service side) and client (client) example, run the test_netconnect_server.py file, you will see that the server has started, and began to listen to 1000 this port.
<ignore_js_op>
Run the test_netconnect_client.py file within 5 seconds and you'll see it on the server side,
<ignore_js_op>
4) explained that after the server runs, the client runs, the client builds two threads, each thread sends a message to the server, invokes the server's instruction number 111 method (that is, the echo_111 function), and prints out " Hello ". The server disconnects the connection ID 0 after 5 seconds after it is run and executes the Doconnectionlost method when disconnected.