ChatMesh is a real-time messaging system built on .NET for peer chat and AI agent message dispatching. It is designed as an easier and safer way to run private agent-to-human or agent-to-agent communication on infrastructure you control, instead of depending on public messaging services such as Telegram, Discord, or WeChat. The repository includes a WebSocket server, a reusable client library, a .NET MAUI UI client, shared message contracts, and an automated server test suite.
ChatMesh is structured around targeted conversations routed through a central WebSocket server.
- The server listens on port
4040by default. - Clients authenticate with a username and token.
- Each client connects with a
peerUsername, and the server only routes that conversation's messages. - Message payloads are JSON serialized and include system, chat, join, and leave events.
- Chat messages can optionally be encrypted end-to-end between two peers with a shared message encryption key.
- The same routing model can be used for user chat, AI agent dispatching, or hybrid user/agent communication.
- You can deploy your own private communication server and keep agent traffic within your own environment.
- Direct messaging between authenticated users.
- AI agent to AI agent message dispatching.
- User to agent and agent to user messaging.
- Explicit point-to-point routing where each client is bound to a named peer.
- Easier integration path for AI agents than adapting a public social or chat platform.
- Safer private communication model because the server can run entirely under your own control.
- No dependency on public messaging services such as Telegram, Discord, or WeChat.
- Simple peer-based routing that is easier to reason about for agent dispatch flows.
- Optional shared-key message encryption for private peer-to-peer message content.
- Shared contracts and reusable client code to keep agent messaging implementations consistent.
-
src/ChatMesh.ServerWebSocket host built onSuperSocket.WebSocket.Server. -
src/ChatMesh.ClientReusable .NET client library for connecting, dispatching messages, and receiving payloads. -
src/ChatMesh.MauiClientMAUI application with chat and settings UI. -
src/ChatMesh.ContractShared message payload models and serializer. -
src/ChatMesh.Server.AbstractionsShared server-side interfaces and request models. -
tests/ChatMesh.Server.TestsUnit and end-to-end tests for serialization, authentication, in-memory message routing, and WebSocket flows. -
tools/GenHashSmall helper for generating a salted token hash entry.
-
assets/chatmesh-logo.svgPrimary ChatMesh logo for repository and documentation use. -
src/ChatMesh.MauiClient/Resources/AppIcon/appicon.svgMAUI app icon background layer. -
src/ChatMesh.MauiClient/Resources/AppIcon/appiconfg.svgMAUI app icon foreground layer generated from the ChatMesh logo mark.
ChatMesh.slnx
Directory.Build.props
Directory.Packages.props
src/
ChatMesh.Client/
ChatMesh.Contract/
ChatMesh.MauiClient/
ChatMesh.Server/
ChatMesh.Server.Abstractions/
tests/
ChatMesh.Server.Tests/
tools/
GenHash/
The server entry point is in src/ChatMesh.Server/Program.cs.
- Uses
Host.CreateDefaultBuilder(args)and SuperSocket WebSocket hosting. - Registers
ChatMeshMiddlewarefor authentication, welcome messages, routing, and session lifecycle handling. - Stores authentication users in
appsettings.jsonunder theAuthsection.
The reusable client is ChatMesh.Client.ChatClient.
- Connects to
ws://orwss://endpoints. - Sends
username,token,peerUsername, and optionallastMessageIdas query parameters. - Accepts an optional message encryption key during connect.
- Raises
MessageReceivedandConnectionStateChangedevents. - Tracks the last received message ID to support reconnect without replaying already-read chat messages.
- Encrypts
ChatMessagePayload.Contentbefore send and decrypts it after receive when a shared message encryption key is configured. - Can be used as a transport client for AI agents exchanging addressed messages over the ChatMesh server.
The MAUI app exposes a simple operator-facing chat experience.
ChatPageshows connection status, message history, and send controls.SettingsPagestores server host, username, token, peer username, and an optional message encryption key.AppShelllaunches directly into the chat page.
Authentication is token-based.
- The server compares the provided token against a salted hash in
src/ChatMesh.Server/appsettings.json. - The repository configuration includes users such as
alice,bob, andTradeAgent. - Plaintext tokens are not stored in server configuration.
In an agent dispatch setup, each agent can be represented as a named authenticated identity with its own token.
Example auth entry shape:
{
"Username": "alice",
"Salt": "...",
"HashedToken": "..."
}ChatMesh supports optional peer message encryption for ChatMessagePayload.
- Two peers can share the same message encryption key.
- If a key is configured, outgoing chat message content is encrypted in the client before transport.
- If the receiving peer has the same key configured, the content is decrypted after receipt.
- The
ChatMessagePayload.Encyptedflag indicates that the payload content was transported in encrypted form.
This is useful when you want private message content between peers while still running your own private ChatMesh server.
- .NET SDK 10
- macOS with MAUI workload and Xcode tooling if building iOS or Mac Catalyst targets
- Android or Windows platform toolchains if building those targets
The repo uses central MSBuild configuration.
Directory.Build.propscentralizes framework settings.Directory.Packages.propscentralizes NuGet package versions.
Non-MAUI projects use:
$(ChatMeshTargetFrameworks)
The MAUI project uses:
$(ChatMeshMauiTargetFrameworks)
Restore and build the server-side projects:
dotnet build tests/ChatMesh.Server.Tests/ChatMesh.Server.Tests.csprojRun the test suite:
dotnet test tests/ChatMesh.Server.Tests/ChatMesh.Server.Tests.csprojBuild the MAUI client for Mac Catalyst on macOS:
dotnet build src/ChatMesh.MauiClient/ChatMesh.MauiClient.csproj -f net10.0-maccatalystBuild the reusable client library:
dotnet build src/ChatMesh.Client/ChatMesh.Client.csprojRun the server:
dotnet run --project src/ChatMesh.Server/ChatMesh.Server.csproj- Start the server.
- Open the MAUI client or connect through the reusable client library.
- Configure the following settings:
- Server host, for example
localhost:4040 - Username
- Authentication token
- Peer username
- Server host, for example
- Optional message encryption key shared with the peer
- Connect from two users, two agents, or a user and an agent whose usernames reference each other as peers.
- Exchange messages through the server.
ChatMesh is intended to be usable as a lightweight dispatch layer for AI agents.
- Assign each agent a unique username and token.
- Set
peerUsernameto define the dispatch target. - Optionally share a message encryption key between peers when private message content is required.
- Reuse the shared contract project so payload formats remain consistent.
- Use the client library for agent transports or build custom clients on the same message protocol.
This makes ChatMesh suitable for small agent meshes, operator-to-agent messaging, and explicit point-to-point agent routing. For teams that want a private alternative to public chat platforms, ChatMesh provides a straightforward way to stand up an internal dispatch server for AI agents and controlled human/operator access.
Shared payloads live in src/ChatMesh.Contract.
ChatMessagePayloadSystemMessagePayloadUserJoinedPayloadUserLeftPayload
Serialization is handled by MessageSerializer.
For chat payloads, ChatMessagePayload also includes an Encypted flag to indicate encrypted message transport.
The helper in tools/GenHash prints a username|salt|hash style line for a token entry.
Run it with:
dotnet run --project tools/GenHash/GenHash.csprojIf you want different input values, update tools/GenHash/Program.cs accordingly.
- End-to-end server tests currently pass, but you may still see expected teardown-time WebSocket logging noise from
ChatMeshMiddlewarewhen sessions close. - The repository root folder can still be named
AIChatMeshlocally even though the solution and projects are now namedChatMesh.
- Language version and target framework are .NET 10 / C# 13 style.
- Nullable reference types are enabled.
- The codebase uses centralized package management.