Net-informations.com
SiteMap  | About    

C# Multi threaded socket programming

C# Multithreaded Socket Programming describes that a Multithreaded Socket Server can communicate with more than one client at the same time in the same network. 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 chapter C# Socket Programming describes a Server Socket Program can communicate with only one client at a time . That means, the C# Server Socket Program does not accept more than one C# Client Socket Program connection . From the following picture you can understand how to a C# Multithreaded Server can communicate with more than one C# Client at the same time .You can see the basics of Socket Programming in the previous section , before you start this section take a look at C# Socket Programming .

csharp-multithreaded-socket-programming-1

The basic idea behind Multithreaded Socket Programming is, whenever the Server gets a connection request from Client side, the Server create a separate Client Thread in Server side for communicate with that particular Client Socket. That means, for each Client Socket there is a separate Client Thread in Server side for independent communication. So the Client can communicate independently with their own Client Thread in the Server side.

csharp-multithreaded-socket-programming

In the following sections you can see in details of How to a C# Multithreaded Socket Programming can communicate with more than one client at the same time.

The C# Multithreaded Socket Programming has two sections.

1. C# Multi Threaded Server Socket Program

2. C# Multi Threaded Client Socket Program

How to run this program ?

Create C# Multi Threaded Server Socket Program and C# Multi Threaded Client Socket Program in two separate C# projects .

After compile and build the projects, open a DOS prompt and run the Server Program first. Then you will get the message "Server started" in Server side.

Next you start the Client program , then you can see the message from Server . You can start more than one client at the same time and communicate with the Server program. If you plan to run more than one client, it is better to run the client program's .exe file to copy in separate folders and run from .exe file.









net-informations.com (C) 2017    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.