public void Close()
 {
     if (!portIsTcp)
     {
         this.udpClient.Close();
         this.udpClient = null;
     }
     else
     {
         this.tcpServer.Close();
         this.tcpServer = null;
     }
 }
        public void Connect(bool tcp)
        {
            portIsTcp = tcp;
            if (!tcp)
            {
                if (this.udpClient != null) Close();
                this.udpClient = new UdpClient(this.remoteHost, this.remotePort);
            }
            else
            {
                this.tcpServer = new TcpServer(this.remotePort);
                tcpServer.TCPClientConnected+=new ClientConnectedEventHandler(tcpServer_TCPClientConnected);

            }
        }