private void StartServer()
{
TcpListener server = new TcpListener(IPAddress.Any, 1234);
server.Start();
Socket socket;
ChatSession chatSession;
while (true)
{
// blocks until a connection is established
socket = server.AcceptSocket();
// when this fires the socket will be connected and the connection
// will actually be setup on a port other than 1234. this allows
// us to keep servicing future requests on port 1234.
// for long running processes, the key is to somehow pass the socket
// off to another thread. if you dont do this the server will
// not be able to establish new connections while the process is still
// running.
chatSession = new ChatSession(socket);
chatSessions.Add(chatSession);
}
}