So, I am writing this school project, which should be a basic chat program consisting of a client and a server. I am trying to process either a server or closed client programs.
So, when you click the big red X in the client window, this happens:
private void Window_Closing(object sender, CancelEventArgs e) { Data msgToSend = new Data(); msgToSend.cmdCommand = Command.Logout; msgToSend.strName = LoginName; byte[] b = msgToSend.ToByte(); ClientSocket.Send(b); }
It sends a message to the server with a message that someone is logging out, so he can remove the user from the list of users, etc.
The problem occurs when the server shuts down and tries to send a message to clients, telling them that the server has shut down, so clients can inform users and then close.
So, the server message appears, and the client program is about to close, but the above code will try to inform the server falsely about logging out, but by this time the server is already disconnected, so there will be a lot of error messages.
I assume that in the procedure described above, I will need some kind of "if" statement that can decide if the code should work, but I have no idea what it should be. Ideas?
lacer source share