private void UdpListener() { udpActive = true; while (udpActive) { if (UdpConnected) { try { bytes = udpClient.Receive(ref ipEndPoint); } catch (SocketException) // receive timeout { continue; } Packet packet = Packet.Populate(Encoding.ASCII.GetString(bytes)); PacketReceived(this, new PacketReceivedEventArgs(ProtocolType.Udp, packet)); } Thread.Sleep(10); } udpClient.Close(); }
private void TcpListener() { tcpActive = true; while (tcpActive) { if (TcpConnected) { if (stream.DataAvailable) { int i; while (stream.DataAvailable && (i = stream.Read(bytes, 0, bytes.Length)) != 0) { Packet packet = Packet.Populate(Encoding.ASCII.GetString(bytes, 0, i)); PacketReceived(this, new PacketReceivedEventArgs(ProtocolType.Tcp, packet)); } } } Thread.Sleep(10); } tcpClient.Close(); }