//----------------------------------------------------------------------------------------- private void GetTcpPackets(TCPClient client) { try { Socket socket = client._socket; NetworkStream stream = client._stream; BinaryReader reader = client._reader; BinaryWriter writer = client._writer; if (stream.DataAvailable) { int noOfIncomingBytes = reader.ReadInt32(); byte[] bytes = reader.ReadBytes(noOfIncomingBytes); Packet packet = _serializer.Deserialize(bytes); if (CheckForUsernamePacket(packet)) { // no need to add to packetlist because it has been delt with. client._name = packet.sender; } if (CheckForDisconnect(packet)) { RemovingClient(packet.sender); } else { _packetList.Add(packet); } } } catch (Exception e) { Console.WriteLine("Error occured: " + e.Message); } }
private void AcceptSocket() { socket = server.AcceptSocket(); client = new ServerLibrary.TCPClient(socket, "Tester"); }