1. Create a project Enter the firefly-admin.py createproject chat_rooms (Linux at the terminal ), <Ignore_js_op> Firefly creates a project named chat_rooms under the MSI folder in the users directory of drive C. <Ignore_js_op>
2. Import the project Import the project to eclipse <Ignore_js_op> 3. Configure Parameters Configure parameters in config. JSON <Ignore_js_op> 3. Configure Parameters Configure parameters in config. JSON <Ignore_js_op> The port configuration in the master is as follows: Rootport is the Management port of the master service, Webport is the external http port of the master service. It manages various service processes through web interfaces. Server Configuration: Testserver is the server we want to run, Netport is the port that the server listens, Name is the server name, The app is the corresponding file path and file name at startup, App. Server indicates the Server File under the app module.
(Multiple services can be configured, such as scenarios and chat servers required for Online Game Development) DDB is a database configuration Host is the database service address. User is the Database User Name Passwd is the Database Password Port is the database connection port. DB is the database name Charset is the encoding of the Database Connection Client. 4. write code Create the server. py file in the corresponding path of the server configuration app filled in above. The Code is as follows: <Ignore_js_op> Line 3: Introduce the netservicehandle method from Firefly (this method is defined in Firefly and can be called directly. The specific function is to modify the logic code of the game. In this example, the server listens to the port 1000. When the client sends the command Number 111, netservicehandle calls all the methods it modifies Based on 111. The method is called xxx_111. In this example, It is speak_10001, therefore, when developing a game, the command number must be repeated ). Rows 1 and 16 define the operations performed after the connection is established and the connection is disconnected (that is, the user goes online and offline ). Lines 23,24 bind the custom method above to the Framework Line 3: Use netservicehandle as the modifier to modify the functions to be defined below. Row 3 defines the speak_10001 method to process requests from the client. This is the simplest chat server. When you start it, It listens to port 1000. When a client sends a message, it sends messages sent from the client to other online users for chat. 5. Check the server 1) Compile a simple client with the following code: <Ignore_js_op> <Ignore_js_op> After the connection is established, the client enables two threads, one for sending messages and the other for receiving messages. 2) Running Server <Ignore_js_op> The red line indicates that the server whose name is chat has started to work. 3) run the client Start chatting. Client 1 and client 2 greet each other, and client 3 goes into disorder: <Ignore_js_op> <Ignore_js_op> <Ignore_js_op>12. PNG (14.8 kb, downloads: 578) Download the attachment and save it to the album. Upload at a.m. on February 14
OK. The server is correct.
<Ignore_js_op> chat_rooms.rar (3.26 kb, downloads: 201) <Ignore_js_op> client.rar (852 bytes, downloads: 185)
|
Use firefly to write simple chat rooms