So I have created a client and a server howerver whenever I run multiple clients and then close 1 of them the other clients disconnect as soon as they try to message other active clients. This may be due to a mistake inside my code however I still cant manage to find where the problem lies.
Whenever I close a client I call this code:
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
Socket_Client.Close();
}
Below is a link to another post where I have displayed the entire code which I currently use. I have created a post on this site giving more information regarding my problem. Any help will be greatly appreciated.
c# - Disconnecting from server close all other connections when I try to send message to a connected user - Stack Overflow[
^]
What I have tried:
I have tried to locate the problem and found that withing the method
private void doChat()
Both the method :
networkStream.Read(bytesFrom, 0, (int)clientSocket.ReceiveBufferSize);
dataFromClient = System.Text.Encoding.ASCII.GetString(bytesFrom);
dataFromClient = dataFromClient.Substring(0, dataFromClient.IndexOf("$"));
Console.WriteLine("From client - " + clNo + " : " + dataFromClient);
rCount = Convert.ToString(requestCount);
Program.broadcast(dataFromClient, clNo, true);
And the catch method is Fired.
The output I get on server which is a console based application is for example
The server is listening
client1 joined
client2 joined
client3 joined
client1 disconnected
client2 says hey
client2 disconnected
As the example displayed once 1 client is disconnected it seems to close all the clients whenever I try to send a message to the connected clients.
Any help will be greatly appreciated. I have been stuck on this problem for quite some time as I am new to coding with server / client application.