/// <summary> /// Constructs a new client /// </summary> public Client() { buffer = new NetworkBuffer(); buffer.WriteBuffer = new byte[writeBufferSize]; buffer.ReadBuffer = new byte[readBufferSize]; buffer.CurrentWriteByteCount = 0; }
/// <summary> /// Runs in its own thread. Responsible for accepting new clients and kicking them off into their own thread /// </summary> private void ListenForClients() { listener.Start(); while (started) { TcpClient client = listener.AcceptTcpClient(); Thread clientThread = new Thread(new ParameterizedThreadStart(WorkWithClient)); Console.WriteLine("New client connected"); NetworkBuffer newBuff = new NetworkBuffer(); newBuff.WriteBuffer = new byte[sendBufferSize]; newBuff.ReadBuffer = new byte[readBufferSize]; newBuff.CurrentWriteByteCount = 0; clientBuffers.GetOrAdd(client, newBuff); clients.Add(client); clientThread.Start(client); Thread.Sleep(15); } }