コード例 #1
0
        //初始化按钮
        private void btnInitial_Click(object sender, EventArgs e)
        {
            ServerA = new ServerSocket();
            ServerB = new ServerSocket();

            URControllerA = new URControlHandle();
            URControllerB = new URControlHandle();

            //按钮的可用和不可用确保只会初始化一次
            this.btnInitial.Enabled = false;
            this.btnReset.Enabled   = true;

            ServerIP = txtIPAddressPC.Text;
            ServerA.server_listenPort = Convert.ToInt32(txtPortPCToRobotA.Text);
            ServerB.server_listenPort = Convert.ToInt32(txtPortPCToRobotB.Text);

            ClientAIP   = txtIPAddressRobotA.Text;
            ClientAPort = Convert.ToInt32(txtPortRobotA.Text);

            ClientBIP   = txtIPAddressRobotB.Text;
            ClientBPort = Convert.ToInt32(txtPortRobotB.Text);

            //AB两台机器分开
            try
            {
                ServerA.Create_Server();
                ServerA.OnConnectionSuccess += new ServerSocket.ConnectionSuccess(ConnectOverA);
                ServerA.OnReceiveSuccess    += new ServerSocket.ReceiveSuccess(ReceiveOverA);
                ServerA.OnClientDisconnect  += new ServerSocket.ClientDisconnect(DisconnectOverA);

                URControllerA.Creat_client(ClientAIP, ClientAPort);
            }
            catch (Exception ConnectError)
            {
                MessageBox.Show("无法连接A机器" + ConnectError.ToString());
            }

            try
            {
                ServerB.Create_Server();
                ServerB.OnConnectionSuccess += new ServerSocket.ConnectionSuccess(ConnectOverB);
                ServerB.OnReceiveSuccess    += new ServerSocket.ReceiveSuccess(ReceiveOverB);
                ServerB.OnClientDisconnect  += new ServerSocket.ClientDisconnect(DisconnectOverB);

                URControllerB.Creat_client(ClientBIP, ClientBPort);
            }
            catch (Exception ConnectError)
            {
                MessageBox.Show("无法连接B机器" + ConnectError.ToString());
            }
        }