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))