while (!Server.isShuttingDown)
{
Server.client = Server.listener.AcceptTcpClient();
Connection con = new Connection(Server.client);
}
How do I make it so that the server knows when the client is connected? I made a class for what happens when the client connects but that is useless ’till I make it so that it knows when the client connects.
Well the
AcceptTpcClientmethod will block until a client connects – so insert a line between that and theConnectionconstructor call… or even after it, assuming that theConnectionconstructor starts a new thread.Mind you, it looks like you’re overwriting the value of a single variable variable –
Server.client– on each iteration, which doesn’t sound like a good idea. I suspect you’d be better off with:(It’s not clear why the
Serverobject itself isn’t doing all of this… or at least exposing anAcceptTcpClientmethod itself. Currently this looks like a bit of a violation of the Law of Demeter.)