Example #1
0
        /// <summary>
        /// 心跳30秒执行一次
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void but_heartbeat_Click(object sender, EventArgs e)
        {
            /*
             * REGISTER sip:[email protected] SIP/2.0
             * Call-ID: abedreg;branch
             * Proxy-Info:1002
             * Content-Type:Application/xml
             * Expires:3600
             * Cseq:3 REGISTER
             * From:<sip:[email protected]>;tag=123
             * Max-Forwards:70
             * To:<sip:[email protected]>
             * Content-Length:140
             *
             * <?xml version="1.0" encoding="UTF-8"?>
             * <Message>
             * <DeviceID>[email protected]</DeviceID>
             * <Status>1</Status>
             * </Message>
             */



            Thread t = new Thread(new ParameterizedThreadStart(heartbeat));

            t.IsBackground = true;
            HeartBeatParameter p = new HeartBeatParameter();

            p.second    = 30;
            p.hostIP    = "192.168.0.226";
            p.UserID    = "34020000003000000001";
            p.CameraUrl = p.UserID + "@" + p.hostIP;
            p.Status    = 1;
            t.Start(p);
        }
Example #2
0
        /// <summary>
        /// 定时执行心跳方法
        /// </summary>
        /// <param name="second">间隔时间</param>
        private void heartbeat(object second)
        {
            HeartBeatParameter obj = (HeartBeatParameter)second;

            while (true)
            {
                cacheLock.EnterWriteLock();
                try
                {
                    /*协议体*/
                    StringBuilder strBody = new StringBuilder();

                    strBody.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n");
                    strBody.Append("<Message>\r\n");
                    //  strBody.Append("<DeviceID>[email protected]</DeviceID>\r\n");
                    strBody.Append("<DeviceID>" + obj.CameraUrl + "</DeviceID>\r\n");
                    strBody.Append("<Status>" + obj.Status + "</Status>\r\n");
                    strBody.Append("</Message>\r\n");

                    /*协议头*/
                    int           len       = strBody.ToString().Length;
                    StringBuilder strHeader = new StringBuilder();
                    strHeader.Append("REGISTER sip:[email protected] SIP/2.0\r\n");
                    strHeader.Append("Call-ID: abedreg;branch\r\n");
                    strHeader.Append("Proxy-Info:1002\r\n");
                    strHeader.Append("Content-Type:Application/xml\r\n");
                    strHeader.Append("Expires:3600\r\n");
                    strHeader.Append("Cseq:3 REGISTER\r\n");
                    strHeader.Append("From:<sip:[email protected]>;tag=123\r\n");
                    strHeader.Append("Max-Forwards:70\r\n");
                    strHeader.Append("To:<sip:[email protected]>\r\n");
                    strHeader.Append("Content-Length:" + len + "\r\n\r\n");

                    string contentStr = strHeader.ToString() + strBody.ToString();
                    /*发送指令*/
                    string sendStr   = contentStr;
                    byte[] sendBytes = Encoding.GetEncoding("gb2312").GetBytes(sendStr);
                    int    num       = clientSocket.Send(sendBytes);
                    /*接收返回值*/
                    string recStr   = "";
                    byte[] recBytes = new byte[4096];
                    int    bytes    = clientSocket.Receive(recBytes, recBytes.Length, 0);
                    recStr += Encoding.GetEncoding("gb2312").GetString(recBytes, 0, bytes);
                    SetText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + recStr + "/n/r");

                    // txt_Recevicecontext.Text += recStr + "/n/r";
                }
                finally {
                    Thread.Sleep(1000 * obj.second);
                    cacheLock.ExitWriteLock();
                }
            }
        }
Example #3
0
        private void but_heartbeat_Click(object sender, EventArgs e)
        {
            HeartBeatParameter p = new HeartBeatParameter();

            p.second    = 30;
            p.hostIP    = "192.168.0.226";
            p.hostIP    = txtIp.Text.Trim();
            p.UserID    = "34020000003000000001";
            p.UserID    = "34020000003000000001";
            p.CameraUrl = p.UserID + "@" + p.hostIP;
            p.Status    = 1;
            int port = int.Parse(txtPort.Text);

            p.port = port;
            Thread t = new Thread(new ParameterizedThreadStart(heartbeat));

            t.IsBackground = true;
            t.Start(p);
        }
Example #4
0
        private void heartbeat(object obj)
        {
            HeartBeatParameter p      = (HeartBeatParameter)obj;
            string             recStr = "";

            while (true)
            {
                cacheLock.EnterWriteLock();
                try
                {
                    recStr = bllCameraControl.heartbeatII(p);
                }
                finally
                {
                    SetText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + recStr + "/n/r");

                    cacheLock.ExitWriteLock();
                    Thread.Sleep(1000 * p.second);
                }
            }
        }
Example #5
0
        /// <summary>
        /// 定时执行心跳方法
        /// </summary>
        /// <param name="second">间隔时间</param>
        public void heartbeat(HeartBeatParameter second)
        {
            HeartBeatParameter obj = second;

            if (clientSocket == null)
            {
                ConnectSocket(obj.hostIP, obj.port);
            }
            while (true)
            {
                /*协议体*/
                StringBuilder strBody = new StringBuilder();

                strBody.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n");
                strBody.Append("<Message>\r\n");
                //   strBody.Append("<DeviceID>[email protected]</DeviceID>\r\n");
                strBody.Append("<DeviceID>" + obj.UserID + "</DeviceID>\r\n");
                strBody.Append("<Status>" + obj.Status + "</Status>\r\n");
                strBody.Append("</Message>\r\n");

                /*协议头*/
                int len = strBody.ToString().Length;

                string strheader  = GetAgreementHeader(1002, len);
                string contentStr = strheader.ToString() + strBody.ToString();
                /*发送指令*/
                string sendStr   = contentStr;
                byte[] sendBytes = Encoding.GetEncoding("gb2312").GetBytes(sendStr);
                int    num       = clientSocket.Send(sendBytes);
                /*接收返回值*/
                string recStr   = "";
                byte[] recBytes = new byte[4096];
                int    bytes    = clientSocket.Receive(recBytes, recBytes.Length, 0);
                recStr += Encoding.GetEncoding("gb2312").GetString(recBytes, 0, bytes);


                Thread.Sleep(1000 * obj.second);
            }
        }