|
The basic function of the Chat Server here is to listening for the connection request from Clients and when the Server get a message , it Broadcast the message to all Clients currently connected to the Server .
The VB.NET Multithreaded Chat Server Program has two sections.
1. Chat Server
2. Chat Client
The Chat Server here is a VB.NET Console based application and is listening to the PORT 8888 for the connection request from clients . When the server gets a connection request , it add the name of the Client into a clientsList ( Here it is a Hashtable ) and create a new thread for communication with Server . When the Server get a message from any client , it select all the Clients from clientsList and send the message to all Clients ( ie we can say Broadcast ) in the clientsList . So each Client can see the message each other and they can communicate through Chat Server.
The client list we implemented here in a HashTable . The clientsList stores the Client Name ( ie the first message from Client ) and an instance of the Client Socket .
When a Chat Client connected to Server , the Server create a new Thread for communication . Here we implement a Class handleClient for handling Client as a separate Thread . The Class handleClient has a function doChat() is handling the communication between the Server side Client Socket and the incoming Client Socket.
When Server get a message from any of the currently connected Chat Client , the Server Broadcast the message to all Clients. Here we implement a function broadcast for sending messages to all Clients .
Create a new VB.NET Console based application and put the following source code into the Project.
VB.NET SourceCode
Download Chat Server Program .
Chat Server Download
Chat Client Download
Refer to Chat Server Program for how to run this program .
|