date: 2024-05-01
title: Chat-Application
status: DONE
author:
- AllenYGY
tags:
- Project
- Network
- Cpp
- Document
created: 2024-05-01T14:28
updated: 2024-06-11T01:14
publish: True
A chat application allows users to interact or communicate by texting, audio, and video. It can be useful for social or commercial activities.
In this assignment, students are required to write a Chat Program based on Windows Socket Programming C++.
The program should allow users to chat concurrently on the Internet (i.e., User A can send encrypted messages to User B, and vice versa).
You can download the sample programs (namely, “server.cpp” and “client.cpp”) from the Web site. The program should consist of the following modules:
User Management: Implemented By Server
Group chat: Group started by Client
Management of connections: Give every User a Threads
起初,我们的客户端实现仅采用了单线程方式,消息的接收和发送是交替进行的。这种实现方式存在一个显著的问题:客户端无法同时进行消息的接收和发送操作,而是只能在完成接收后进行发送,反之亦然。这导致了客户端在等待接收或发送消息时会发生阻塞,影响用户体验。
为了克服这一问题,我们引入了多线程技术。在客户端中,我们分别为消息的接收和发送操作创建了独立的线程,从而实现了这两项操作的并发处理。这一改进使得客户端可以同时进行消息的接收和发送,提高了响应速度和用户体验。
在服务器端,我们引入了互斥锁(mutex)来确保数据传输的正确性和线程安全性。当多个用户向同一个用户发送消息时,服务器会将这些消息推送到该用户的消息队列中,并在这一过程中使用互斥锁来保证消息的有序和完整传输。这样,服务器能够在多用户环境下稳定、高效地管理消息队列,确保每个用户都能正确收到发送给他们的消息。
I'm going to talk some details about how we implemented this chat room application.
To solve this, we introduced multithreading.
Separate threads for receiving and sending to improve responsiveness and user experience.
These changes enabled the server to efficiently manage message queues in a multi-user environment, ensuring each user correctly receives their messages.