HLW chat room - a multi-person chat tool developed using Linux C network programming technology
Installation and deployment
git clone https://github.com/fujie-xiyou/chat_room.git
Then import chat_room.sql
into your database, and modify the database information in config.json
Finally, if no error is reported in ./chat_room_srv
, the server will start successfully.
Then modify the server address in config.json and finally ./chat_room_cli
Please register an account first
Demo video
Chat room video demo
Project overview
- This project is a character interface chat room developed using Linux C network programming technology. The basic functions include user registration and login, adding friends, private chat, creating group chat, inviting friends to join group chat, group chat, chat record viewing, and file transfer. wait.
Project design
- This project is designed based on the C/S model and is divided into two parts: client and server. The client is directly connected to the server and exchanges data with the server in both directions. The server is used to receive messages from the client and forward them to the target user. , all data persistence work is also completed on the server side.
- The project code is designed using a layered idea. The client is composed of the interface layer and the business logic layer (request layer), and the server is composed of the business logic layer and the persistence layer. The code structure is as follows:
- Database design
- When this project was developed, I had not systematically studied database-related courses, but later when I reviewed the database design of this project, I found that it was in line with the BC paradigm.
- Some examples of the project database are shown in the figure
- File transfer function design Since the client and server of this project use JSON for data interaction, special processing is required for file transfer. Therefore, here is a brief introduction to the processing method of file transfer. First, the above picture:
- As shown in the figure, after the user enters the file name to be sent, the system uses the open() system call to open the file, then uses the read() system call to read the file content of the specified bytes, and records the return value of read in the size of the data packet. field, and then use base6 to read the file content 4. Transcode, record the result in the data field of the data packet, and then send the data packet to the receiver, and then judge whether all the files have been sent based on the size of the read return value. If the read return value is smaller than the read size parameter, Then close the file, otherwise continue reading, transcoding and sending.
- After receiving the file package, the receiver decodes the data in data into binary, and then appends the data in the buff that stores the transcoding result of data to the file according to the value of size.