public void Send(Encapsulation_Packet SendPkt)
 {
     try
     {
         Tcpclient.Client.Send(SendPkt.toByteArray());
     }
     catch
     {
         Trace.WriteLine("Error in TcpClient Send");
         Tcpclient = null;
     }
 }
        public int SendReceive(Encapsulation_Packet SendPkt, out Encapsulation_Packet ReceivePkt, out int Offset, ref byte[] packet)
        {
            ReceivePkt = null;
            Offset     = 0;

            int Lenght = 0;

            try
            {
                // We are not working on a continous flow but with query/response datagram
                // So if something is here it's a previous lost (timeout) response packet
                // Flush all content.
                while (Tcpclient.Available != 0)
                {
                    Tcpclient.Client.Receive(packet);
                }

                Tcpclient.Client.Send(SendPkt.toByteArray());
                Lenght = Tcpclient.Client.Receive(packet);
                if (Lenght > 24)
                {
                    ReceivePkt = new Encapsulation_Packet(packet, ref Offset, Lenght);
                }
                if (Lenght == 0)
                {
                    Trace.WriteLine("Reception timeout with " + Tcpclient.Client.RemoteEndPoint.ToString());
                }
            }
            catch
            {
                Trace.WriteLine("Error in TcpClient Send Receive");
                Tcpclient = null;
            }

            return(Lenght);
        }
 public void Send(Encapsulation_Packet Packet, IPEndPoint ep)
 {
     byte[] b = Packet.toByteArray();
     m_exclusive_conn.Send(b, b.Length, ep);
 }