How to C# Chat server programming

Network programming in windows is possible with Sockets .The Microsoft .NET framework provides two namespaces, System.Net and System.Net.Sockets for managed implementation of Internet protocols that applications can use to send or receive data over the Internet .

In the previous section C# Multi Threaded Socket Program we can see a C# Multi Threaded Server Socket Program communicate with more than one Client at the same time . But there the communication is occurred between Server to Client or Client to Server , there is no communication between Client to Client . C# Chat Server describes how to a Client can communicate with any number of Clients , currently connected to the Chat Server.


The main idea behind the C# Chat Server is that each Client send messages to the Server and the Server broadcast the message to all Clients currently connected to the Chat Server . From the following picture you can see how a C# TCP Chat Server is handling communication between Client to Client.


C# chat server example

The C# Chat Server program has two sections.

1. C# Chat Server

2. C# Chat Client

How to run Chat Server program ?

Create the C# Chat Server and C# Chat Client are two separate C# projects and compile and build the program. Open a DOS prompt and run the Server Program first and then run the Client program .

In the Client program, Enter a Chat name and click " Connect to Server " button . Then you can see the message in the Server program User " Joined Chat Room " . Similarly you can connect more than one Clients at the same time and start chatting each other. If you plan to run more than one client, it is better to copy the .exe file in separate folders and run from the .exe file.
 (C) 2021    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.
SiteMap  | Terms  | About