Java chat room program source code
2 Requirements analysis
2.1 Business needs
1. Chat with chat room members.
2. You can chat privately with chat room members.
3. You can change the chat content style.
4. User registration (including avatar) and login.
5. The server monitors the chat content.
6. The server filters illegal content.
7. The server sends a notification.
8. Server kicks people.
9. Save the server log.
10. Save user chat information.
2.2 System function modules
2.2.1 Server side
1. Process user registration
2. Handle user login
3. Process information sent by users
4. Process the information obtained by the user
5. Handle user exit
2.2.2 Client
1. User registration interface and results
2. User login interface and results
3. User sending information interface and results
4. The user gets the information interface and results
5. User exit interface and results
2.3 Performance requirements operating environment: Windows 9x, 2000, xp, 2003, Linux
Necessary environment: JDK 1.5 or above Hardware environment: CPU 400MHz or above, memory 64MB or above
3.1.2 Client structure
ChatClient.java is the client program startup class and is responsible for the startup and exit of the client.
Login.java is the client program login interface, responsible for verification and feedback of user account information.
Register.java is the client program registration interface, responsible for registration verification and feedback of user account information.
ChatRoom.java is the main interface of the client program chat room, responsible for receiving and sending chat content and closely cooperating with the server-side Connection.java.
Windowclose is an internal class of ChatRoom.java, responsible for monitoring the operations of the chat room interface and returning information to the server when the user exits.
Clock.java is a small program of the client program that implements a quartz clock function.
3. 2 System implementation principle
When the user is chatting, the current user name, chat object, chat content, chat tone and whether to chat privately are encapsulated, then a Socket connection is established with the server, and then the object output stream is used to wrap the Socket output stream to send the chat information object to the server. When a user sends a chat message, the server will receive the chat message object transmitted by the client using Socket, and then convert it into a Chat object, and add the user's chat message object to the chat object set Message. for all chat users to access.
Receiving the user's chat information is implemented by multi-threading technology, because the client must always pay attention to whether there is the latest news on the update server. In this program, it is set to refresh the server every 3 seconds. If the interval is too short, the number of customers will increase. The communication burden between the end and the server, and a long interval will make people feel that there is no timeliness, so after weighing it, 3 seconds is considered the best, because it is impossible for every user to send information continuously within 3 seconds.
Each time a user receives a chat message, the chat message will be analyzed and the information suitable for him or her will be displayed on the chat message interface in a humanized manner.
4.1.1 Problem statement
1. Accept user registration information and save it in a file-based object database.
2. Able to allow registered users to log in to the chat interface and chat.
3. Able to accept private message messages and send them to specific users.
4. The server is running on custom port #1001.
5. The server monitors the user list and user chat information (except private chat).
6. The server kicks people and sends notifications.
7. The server saves the log.
Conclusion This article discussed how to use Java technology to develop a chat room system, which basically meets the characteristics of structure, friendly interface, fast speed, security and stability.
The system focuses on researching and implementing the network application part. According to the implementation, it has a friendly chat interface generation effect and smooth network communication effect. The generated chat room can meet basic chat requirements and has high research value.
The system has the basic functions of current chat rooms: including support for multiple avatars, word colors, tone selection, support for emote, support for private chat, support for online chat friend search, support for split-screen display, support for users to customize their own private avatar, and support for filtering swear words , support guest chat. Block the people you hate and send public messages to all your chat friends. It has the characteristics of fast speed, high stability, occupying less system resources and friendly user interface.
Through the graduation project, I found that my theoretical research and practical work abilities have been improved and I have benefited a lot. At the same time, with the guidance of teachers and the joint help of classmates in the research group, I can summarize the research results in a timely manner, which will undoubtedly be of great help to my future work and study.
Expand