Esempio n. 1
0
        private static void KeepAlive()
        {
            while (true)
            {
                try
                {
                    ReqMediaServerReg req = new ReqMediaServerReg()
                    {
                        Ipaddress           = MyIPAddress,
                        MediaServerHttpPort = MediaServerHttpPort,
                        MediaServerId       = MediaServerId,
                        Secret = Secret,
                        WebApiServerhttpPort = HttpPort,
                        RecordFilePath       = RecordPath,
                    };
                    string reqData = JsonHelper.ToJson(req);
                    try
                    {
                        var httpRet = NetHelper.HttpPostRequest(StreamNodeServerUrl, null !, reqData, "utf-8", 5000);
                        if (string.IsNullOrEmpty(httpRet))
                        {
                            if (ProcessApis.CheckIsRunning(out _) > 0)
                            {
                                ProcessApis.StopServer(out _); //发现streamctrl异常回复,就关掉流媒体服务器
                            }
                        }
                    }
                    catch
                    {
                        if (ProcessApis.CheckIsRunning(out _) > 0)
                        {
                            ProcessApis.StopServer(out _); //发现streamctrl异常回复,就关掉流媒体服务器
                        }
                    }

                    Thread.Sleep(1000 * 2);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("报错了:\r\n" + ex.Message + "\r\n" + ex.StackTrace);
                    continue;
                }
            }
        }
Esempio n. 2
0
        private static void KeepAlive()
        {
            int i = 0;

            while (true)
            {
                i++;
                if (i > 999999999)
                {
                    i = 1;
                }

                try
                {
                    ReqMediaServerReg req = null;
                    if (i == 1 || i % 5 == 0)
                    {
                        req = new ReqMediaServerReg()
                        {
                            Ipaddress           = MyIPAddress,
                            MediaServerHttpPort = MediaServerHttpPort,
                            MediaServerId       = MediaServerId,
                            Secret = Secret,
                            WebApiServerhttpPort  = HttpPort,
                            RecordFilePath        = RecordPath,
                            MediaServerSystemInfo = MySystemInfo.GetSystemInfoObject(),
                        };
                    }
                    else
                    {
                        req = new ReqMediaServerReg()
                        {
                            Ipaddress           = MyIPAddress,
                            MediaServerHttpPort = MediaServerHttpPort,
                            MediaServerId       = MediaServerId,
                            Secret = Secret,
                            WebApiServerhttpPort  = HttpPort,
                            RecordFilePath        = RecordPath,
                            MediaServerSystemInfo = null,
                        };
                    }

                    string reqData = JsonHelper.ToJson(req);

                    try
                    {
                        var httpRet = NetHelper.HttpPostRequest(StreamNodeServerUrl, null !, reqData, "utf-8", 5000);
                        if (string.IsNullOrEmpty(httpRet))
                        {
                            MySystemInfo = null;
                            if (ProcessApis.CheckIsRunning(out _) > 0)
                            {
                                ProcessApis.StopServer(out _); //发现streamctrl异常回复,就关掉流媒体服务器
                            }
                        }
                        else
                        {
                            if (ProcessApis.CheckIsRunning(out _) == 0)
                            {
                                ProcessApis.RunServer(out _); //如果正常返回,但是流媒体没启动,则启动流媒体
                            }
                        }
                    }
                    catch
                    {
                        if (ProcessApis.CheckIsRunning(out _) > 0)
                        {
                            ProcessApis.StopServer(out _); //发现streamctrl异常回复,就关掉流媒体服务器
                        }
                    }

                    Thread.Sleep(2000);
                }
                catch (Exception ex)
                {
                    Logger.Logger.Error("报错了-> " + ex.Message + " -> " + ex.StackTrace);
                    continue;
                }
            }
        }