Beispiel #1
0
        private void button_connect_Click(object sender, EventArgs e)
        {
            string strIP = this.textBox_address.Text.ToString();

            if (strIP.Trim().Equals(""))
            {
                MessageBox.Show("IP地址不能为空!");
                return;
            }
            string strPort = this.textBox_port.Text.ToString();

            if (strPort.Trim().Equals(""))
            {
                MessageBox.Show("端口号不能为空!");
                return;
            }

            int intPort = Convert.ToInt32(strPort);

            m_clientSocket = new ClientSocket(strIP, intPort);
            m_bConnected   = m_clientSocket.ConnectServer();
            string strRecved = null;

            if (m_bConnected)
            {
                try
                {
                    m_clientSocket.ClientSend("?config.IsNetCamera\n");
                    strRecved = m_clientSocket.ClientRecv();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.StackTrace.ToString());
                }
                this.button_parameter.Enabled = true;
                this.button_RunOnce.Enabled   = true;
                this.button_restart.Enabled   = true;
                if (strRecved.Equals("false\n"))
                {
                    this.button_EnvironmentSetting.Enabled = false;
                    MessageBox.Show("已成功连接至服务器, \n\n您正在使用Logitech摄像头!");
                    //SelfMessageBox smb = new SelfMessageBox(m_clientSocket);
                    //smb.ShowDialog(this);
                }
                else if (strRecved.Equals("true\n"))
                {
                    this.button_EnvironmentSetting.Enabled = true;
                    SelfMessageBox smb = new SelfMessageBox(m_clientSocket);
                    smb.ShowDialog(this);
                }
                InitializeTimer(5000);
            }
            else
            {
                this.button_parameter.Enabled = false;
                this.button_RunOnce.Enabled   = false;
                this.button_restart.Enabled   = false;
                m_clientSocket = null;
                MessageBox.Show("连接失败, 请正确配置服务器!");
            }
        }
Beispiel #2
0
        //系统连接按钮事件
        private void button_connect_Click(object sender, EventArgs e)
        {
            string strIP = this.textBox_address.Text.ToString(); //获取IP地址

            if (strIP.Trim().Equals(""))                         //如果IP地址为空
            {
                MessageBox.Show("IP地址不能为空!");                    //弹出对话框
                return;
            }
            string strPort = this.textBox_port.Text.ToString(); //获取端口号

            if (strPort.Trim().Equals(""))                      //如果端口号为空
            {
                MessageBox.Show("端口号不能为空!");
                return;
            }

            int intPort = Convert.ToInt32(strPort);            //得到端口号

            m_clientSocket = new ClientSocket(strIP, intPort); //创建套接字
            m_bConnected   = m_clientSocket.ConnectServer();   //连接服务器
            string strRecved = null;                           //接收到的数据

            if (m_bConnected)                                  //如果服务器连接成功
            {
                try
                {
                    //向服务器发送状态查询指令
                    m_clientSocket.ClientSend("?config.IsNetCamera\n");
                    strRecved = m_clientSocket.ClientRecv(); //从服务器接收返回结果
                }
                catch (Exception ex)
                {
                    //如果通信异常, 给出错误信息
                    MessageBox.Show(ex.StackTrace.ToString());
                }
                this.button_parameter.Enabled = true;               //参数设置按钮有效
                this.button_RunOnce.Enabled   = true;               //运行一次按钮有效
                this.button_restart.Enabled   = true;               //服务器重启按钮有效
                if (strRecved.Equals("false\n"))                    //如果使用的是罗技摄像头
                {
                    this.button_EnvironmentSetting.Enabled = false; //环境设置按钮无效
                    MessageBox.Show("已成功连接至服务器, \n\n您正在使用Logitech摄像头!");
                    //SelfMessageBox smb = new SelfMessageBox(m_clientSocket);
                    //smb.ShowDialog(this);
                }
                else if (strRecved.Equals("true\n"))               //如果使用的是网口摄像头
                {
                    this.button_EnvironmentSetting.Enabled = true; //环境设置按钮有效
                    SelfMessageBox smb = new SelfMessageBox(m_clientSocket);
                    smb.ShowDialog(this);                          //创建并显示环境设置对话框
                }
                InitializeTimer(5000);                             //初始化定时器
            }
            else  //如果服务器连接失败
            {
                this.button_parameter.Enabled = false; //参数设置按钮无效
                this.button_RunOnce.Enabled   = false; //运行一次按钮无效
                this.button_restart.Enabled   = false; //服务器重启按钮无效
                m_clientSocket = null;                 //清理套接字
                MessageBox.Show("连接失败, 请正确配置服务器!");
            }
        }