Skip to content

Firefly Official Tutorials: Netconnect Instructions

9miao Mobile Game edited this page Aug 6, 2014 · 1 revision

Firefly Official Tutorials: Netconnect Instructions

1. Netconnect Introduction

Netconnect contains some handling methods of server to client communication, such as encapsulation of sending data and protocol header, subpackage in TCP communication and stick pack handling.

2. Structural Analysis


LiberateFactory, protocol factory and the essence of all connections, it’s the visualization of server to client communication, includes three parts:
1) LiberateProtocol: communication protocol class, it controls connection establishment and operations after connection break, and sending data.
2) DataPackProtoc: definition of data package protocol, all data analysis must follow the rules it established.
3) ConnectionManager: connection manager controls all connections. You can find your required connection and operate it.
Connection: A connection between server and client is called as object, we can communicate with client, active lose connections and push messages via this object.

3. Example

1) test_netconnect_server.py

2) test_netconnect_client.py

3) The aforementioned images are example of server and client, now you can run test_netconnect_server.py, and see the below image, it shows that sever has been started and is monitoring the 1000 port.

Run test_netconnect_client.py in five seconds and you will see the below image of server:

4) Further explanation: run server ahead of client and it will create two threads after server starts, each thread will send a message that calls command 111 method (that’s function echo_111) of server, printing “hello”. Server will terminate “0” connection after five seconds running and execute doConnectionLost method.