Build a TCP/IP Client & Server Chat App in C#

Fox Learn Guide 8 months ago

Description

🔌 Build a TCP/IP Chat Client–Server App in C# (Step-by-Step Tutorial)

In this video, I’ll walk you through creating a complete TCP/IP chat application in C# .NET 10, using a lightweight library called TcpSharp.

We’ll build both the server (Console App) and the client (Windows Forms App), handle real-time messaging, manage online users, and test everything on a local network.

You’ll learn how to:

🖥️ Server (Console App)

Install and use TcpSharp for handling socket communication

Create a TCP server on port 9000

Handle connection, disconnection, and incoming data events

Manage online users with a dictionary

Broadcast chat messages to all clients

Send private messages to specific users

Maintain and update the user list in real time

💬 Client (Windows Forms App)

Build a clean UI with a Join screen and Chat screen

Save and pass the username across forms

Connect to the server using TcpSharp

Update online users

Display incoming messages

Send direct messages to other users

Keep logs and auto-scroll chat history

🌐 Local Network Setup

Create an app.config to manage host/port

Find local IP using ipconfig

Update the Windows hosts file

Copy the app to another PC and install .NET Framework

Add a new port rule to Windows Firewall.

Test the chat app across multiple computers on the same network

By the end of this tutorial, you'll have a fully working local-network chat app built from scratch.

📌 Coming up next: I’ll show you how to convert the console server into a Windows Service that runs in the background automatically.

👍 If you found this helpful, don’t forget to like, subscribe, and hit the bell so you don’t miss upcoming videos.