private IEnumerator ReceiveTCP() { while (true) { if (tcp_client.Available > 0) { byte[] bytes_size = new byte[4]; stream.Read(bytes_size, 0, 4); int bytesize = BitConverter.ToInt32(bytes_size, 0); byte[] bytes_data = new byte[bytesize]; stream.Read(bytes_data, 0, bytesize); EN_TCP_PACKET_TYPE type = EN_Protocol.BytesToTCPType(bytes_data, 0); TranslateTCP(type, bytes_data); tcpBytesIn += (uint)bytes_size.Length + (uint)bytes_data.Length; } yield return(null); } }
private void ReceiveTCP() { for (int i = 0; i < tcp_clients.Count; i++) { if (tcp_clients[i].Available > 0) { NetworkStream stream = tcp_clients[i].GetStream(); byte[] bytes_size = new byte[4]; stream.Read(bytes_size, 0, 4); int bytesize = BitConverter.ToInt32(bytes_size, 0); byte[] bytes_data = new byte[bytesize]; stream.Read(bytes_data, 0, bytesize); EN_TCP_PACKET_TYPE packet_type = EN_Protocol.BytesToTCPType(bytes_data, 0); IPEndPoint source = (IPEndPoint)tcp_clients[i].Client.RemoteEndPoint; Console.WriteLine("TCP " + (source.Address.ToString() + ":" + source.Port.ToString() + ": " + TranslateTCP(tcp_clients[i], packet_type, bytes_data))); } } }