From 5e9291e03574bec5447229996b1b6cceefd5c106 Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Fri, 29 Nov 2019 11:27:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=90=AF=E5=8A=A8=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/main.cpp | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/server/main.cpp b/server/main.cpp index 82fbd0b9..763de656 100644 --- a/server/main.cpp +++ b/server/main.cpp @@ -235,6 +235,7 @@ int start_main(int argc,char *argv[]) { #endif// #if !defined(_WIN32) + pid_t pid = getpid(); if (bDaemon) { //启动守护进程 System::startDaemon(); @@ -278,21 +279,35 @@ int start_main(int argc,char *argv[]) { TcpServer::Ptr rtspSrv(new TcpServer()); TcpServer::Ptr rtmpSrv(new TcpServer()); TcpServer::Ptr httpSrv(new TcpServer()); - - shellSrv->start(shellPort); - rtspSrv->start(rtspPort);//默认554 - rtmpSrv->start(rtmpPort);//默认1935 - //http服务器 - httpSrv->start(httpPort);//默认80 - //如果支持ssl,还可以开启https服务器 TcpServer::Ptr httpsSrv(new TcpServer()); - //https服务器,支持websocket - httpsSrv->start(httpsPort);//默认443 - //支持ssl加密的rtsp服务器,可用于诸如亚马逊echo show这样的设备访问 TcpServer::Ptr rtspSSLSrv(new TcpServer()); - rtspSSLSrv->start(rtspsPort);//默认322 + + try { + //rtsp服务器,端口默认554 + rtspSrv->start(rtspPort);//默认554 + //rtsps服务器,端口默认322 + rtspSSLSrv->start(rtspsPort); + //rtmp服务器,端口默认1935 + rtmpSrv->start(rtmpPort); + //http服务器,端口默认80 + httpSrv->start(httpPort); + //https服务器,端口默认443 + httpsSrv->start(httpsPort); + //telnet远程调试服务器 + shellSrv->start(shellPort); + }catch (std::exception &ex){ + WarnL << "端口占用或无权限:" << ex.what() << endl; + ErrorL << "程序启动失败,请修改配置文件中端口号后重试!" << endl; + sleep(1); +#if !defined(_WIN32) + if(pid != getpid()){ + kill(pid,SIGINT); + } +#endif + return -1; + } installWebApi(); InfoL << "已启动http api 接口";