This is a WebSocket chat application built with Go and C#. The backend uses Go to provide WebSocket services, while the frontend leverages the Maui Blazor hybrid framework for a modern user interface. The application supports real-time messaging, dynamic user list updates, and broadcast messages. It is implemented via WebSocket for bidirectional communication, making it suitable for learning purposes and small-scale chat applications.
- Logs for user connections, disconnections, and message forwarding.
- Real-time Messaging: Enables users to send and receive messages in real time.
- Broadcast Messages: Admins can send global broadcast messages via the terminal.
- Dynamic User List: Displays active users, automatically updated when users join or leave.
- Avatar Management: Allows users to customize their avatars, with updates visible to others in real time.
- Message Storage: The frontend stores chat history for users to view past conversations.
- Install the latest version of Go.
- Install .NET 9.0.
- Ensure
curl
or another tool is available to test the WebSocket service.
Run the following command:
dotnet workload install maui
Open the project in VSCode
and install the following extensions:
.NET Install Tool
.NET MAUI
C#
Go
-
Navigate to the backend directory
GoChatServer
. -
Start the Go service by running:
go run main.go
-
The WebSocket service will run at
http://localhost:8008/ws
.
-
Navigate to the frontend directory
MyChatApp
. -
Restore project dependencies:
dotnet restore
-
Open the
MauiProgram.cs
file. You should see something like this:- Click
Debug Target
at the bottom. - Run the project by clicking the Run button.
- Click
It is recommended to modify the save location for images in MyChatApp\Components\Layout\ProfilePopover.razor
. Currently, images are saved in the project runtime directory. For production, consider using a third-party hosting service.
The main application logic resides in MyChatApp\Components\Pages
.
- Provides WebSocket services and listens on port
8008
. - Manages user connections, message forwarding, user list broadcasting, and disconnections.
- Built with the
gorilla/websocket
library for WebSocket communication.
Key files and functions:
main.go
: Main program handling user management and message processing.
- Built with Maui Blazor hybrid and MudBlazor frameworks to deliver a modern chat interface.
- Connects to the backend WebSocket service for real-time communication.
- Supports displaying various message types, including system and user messages.
Key files and functions:
Chat.razor
: Chat interface component, responsible for rendering the chat window and user messages.ChatService.cs
: Logic for communicating with the backend WebSocket service.
github.com/gorilla/websocket
: For WebSocket functionality.
MudBlazor
: To create a modern UI..NET WebSocket
: For backend communication.
We welcome suggestions and code contributions to this project:
-
Fork the repository.
-
Create a feature branch:
git checkout -b feature/<your-feature>
-
Commit your changes and submit a Pull Request.
This project is licensed under the MIT License.