From a21ace47dd38e992fcf2208407d95c8c4dc93cd7 Mon Sep 17 00:00:00 2001 From: weizhihong Date: Sun, 8 Oct 2023 09:34:00 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E4=B8=BB=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=88=A4=E6=96=AD=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dynamics/udp.go | 3 +++ main.go | 6 ++---- vobc/udp.go | 3 +++ 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/dynamics/udp.go b/dynamics/udp.go index 0d2e318..7bdbfda 100644 --- a/dynamics/udp.go +++ b/dynamics/udp.go @@ -105,6 +105,9 @@ func (server *udpServer) OnTraffic(c gnet.Conn) gnet.Action { } func RunUdpServer() { + if !config.Config.Dynamics.Open { + return + } server := &udpServer{addr: fmt.Sprintf("udp://:%d", config.Config.Dynamics.UdpLocalPort), multicore: false} err := gnet.Run(server, server.addr, gnet.WithMulticore(server.multicore)) zap.L().Fatal("udp服务启动失败", zap.Error(err)) diff --git a/main.go b/main.go index 1c11776..ca776a9 100644 --- a/main.go +++ b/main.go @@ -40,10 +40,8 @@ func main() { docs.SwaggerInfo.Title = "CBTC测试系统API" engine.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler)) - if config.Config.Dynamics.Open { - go dynamics.RunUdpServer() - go vobc.RunUdpServer() - } + go dynamics.RunUdpServer() + go vobc.RunUdpServer() serverConfig := config.Config.Server if serverConfig.Port == 0 { diff --git a/vobc/udp.go b/vobc/udp.go index fb170e1..e9ed6a6 100644 --- a/vobc/udp.go +++ b/vobc/udp.go @@ -103,6 +103,9 @@ func RegisterTrainInfoHandler(handler VobcDataHandler) { // 创建UDP服务 func RunUdpServer() { + if !config.Config.Dynamics.Open { + return + } server := &udpServer{addr: fmt.Sprintf("udp://:%d", config.Config.Vobc.LocalPort), multicore: false} err := gnet.Run(server, server.addr, gnet.WithMulticore(server.multicore)) zap.L().Fatal("vobc udp服务启动失败", zap.Error(err))