Exemplo n.º 1
0
        private Server addRDPClient(String ip, int port, String username, String password, int timeout)
        {
            Server    server = new Server();
            RdpClient rdp    = null;

            try
            {
                server.ip         = ip;
                server.timeout    = timeout;
                server.serverName = "RDP";
                server.port       = port;
                server.username   = username;
                server.password   = password;
                rdp           = new RdpClient(server);
                server.client = rdp;
                this.rdp_panle.Controls.Add(rdp);
                rdp.OnResponse += rdpResult;
                rdp.Connect(ip, port, username, password);
            }
            catch (Exception e)
            {
                FileTool.log(ip + ":" + port + "-RDP操作异常-" + e.Message);
                LogWarning(ip + ":" + port + "-RDP操作异常-" + e.Message);
                server.isDisConnected = true;
                server.isEndMRE.Set();
            }
            return(server);
        }
Exemplo n.º 2
0
        private static void Main(string[] args)
        {
            SetupDebug();
            if (args.Length != 3 && args.Length != 4)
            {
                Logit("usage: TestRDPClient hostname remotePort localPort <run-incoming-thread>");
                Trace.Flush();
            }

            remoteHostname = args[0];
            remotePort     = int.Parse(args[1]);
            localPort      = int.Parse(args[2]);

            for (int i = 0; i < 1; i++)
            {
                rdpClient = new RdpClient(localPort + i, 100, 1000, true);
                IPHostEntry IPHost = Dns.GetHostEntry(remoteHostname);
                IPAddress[] addr   = IPHost.AddressList;
                IPEndPoint  sendpt = new IPEndPoint(addr[0], remotePort);
                Logit("Connecting to host " + remoteHostname + ", remotePort " + remotePort + ", localPort " + localPort);
                rdpConnection = rdpClient.Connect(sendpt);
                rdpConnection.WaitForState(ConnectionState.Open);
                Logit("Connection successful");
                Thread outgoingThread = new Thread(RunOutgoing);
                outgoingThread.Start();
                if (args.Length == 4)
                {
                    Thread incomingThread = new Thread(RunIncoming);
                    incomingThread.Start();
                }
                while (outgoingThread.IsAlive)
                {
                    Thread.Sleep(500);
                }
            }
            Trace.Flush();
        }
        public TestClass()
        {
            SetupDebug();

            // const int ServerPort = 200;
            const int ServerPort = 5001;
            const int ClientPort = 6666;

            IPHostEntry IPHost = Dns.GetHostEntry("cedeno-dxp.corp.multiverse.net");

            IPAddress[] addr   = IPHost.AddressList;
            IPEndPoint  sendpt = new IPEndPoint(addr[0], ServerPort);


            RdpClient rdpClient  = new RdpClient(ClientPort, 100, 1000, true);
            RdpClient rdpClient2 = new RdpClient(ClientPort + 1, 100, 1000, false);
            //RdpServer rdpServer = new RdpServer(ServerPort, 100, 1000, true);

            RdpConnection rdpClientConn  = rdpClient.Connect(sendpt);
            RdpConnection rdpClientConn2 = rdpClient2.Connect(sendpt);

            // RdpConnection rdpServerConn = rdpServer.Accept();

            rdpClientConn.WaitForState(ConnectionState.Open);
            rdpClientConn2.WaitForState(ConnectionState.Open);

//            Console.WriteLine("Server State = " + rdpServerConn.ConnectionState);
            Console.WriteLine("Client State = " + rdpClientConn.ConnectionState);

            OutgoingMessage outMessage = new OutgoingMessage();

            outMessage.Write("Good morning");
            outMessage.Send(rdpClientConn);

            outMessage.Send(rdpClientConn2);

            // byte[] msg = Encoding.ASCII.GetBytes("Test");

            // rdpClientConn.Send(msg);
            // rdpClientConn.Send(msg);
            // rdpClientConn.Send(msg);

            IPEndPoint      remoteEP = new IPEndPoint(IPAddress.Any, 0);
            IncomingMessage inMessage;

            inMessage = new IncomingMessage(rdpClientConn);
            Console.WriteLine("Got message: {0}", inMessage.ReadString());

            inMessage = new IncomingMessage(rdpClientConn2);
            Console.WriteLine("Got message2: {0}", inMessage.ReadString());

            //            for (int i = 0; i < 3; ++i) {
//                byte[] rcvdMessage = rdpServerConn.Receive(ref remoteEP);
//                Console.WriteLine("Server got message from {1}: '{0}'",
//                                  Encoding.ASCII.GetString(rcvdMessage), remoteEP);
//                rdpServerConn.Send(msg);
//            }
//
//            for (int i = 0; i < 3; ++i) {
//                byte[] rcvdMessage = rdpClientConn.Receive(ref remoteEP);
//                Console.WriteLine("Client got message from {1}: '{0}'",
//                                  Encoding.ASCII.GetString(rcvdMessage), remoteEP);
//            }
//
//            rdpServerConn.Close();

            Thread.Sleep(100);

//            Console.WriteLine("Server State = " + rdpServerConn.ConnectionState);
            Console.WriteLine("Client State = " + rdpClientConn.ConnectionState);

            Thread.Sleep(31000);

//            Console.WriteLine("Server State = " + rdpServerConn.ConnectionState);
            Console.WriteLine("Client State = " + rdpClientConn.ConnectionState);

            FinishDebug();

            //rdpConn.Open(false, 1, 2, 3, 4, true);
            //rdpConn.Send(new Multiverse.Network.Rdp.RdpPacket(50));
            //this.Hide();
            //this.WindowState = FormWindowState.Minimized;
        }