From 7542ee473c444bcce23074ee2945a09e0f9f02e6 Mon Sep 17 00:00:00 2001 From: walker Date: Thu, 19 Oct 2023 14:02:20 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9udp=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E6=9C=AA=E5=90=AF=E5=8A=A8=E7=9B=91=E5=90=AC=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- third_party/dynamics/dynamics.go | 1 + third_party/semi_physical_train/semi_physical_train.go | 1 + third_party/udp/udp_server.go | 4 +++- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/third_party/dynamics/dynamics.go b/third_party/dynamics/dynamics.go index 52d928f..4b18cae 100644 --- a/third_party/dynamics/dynamics.go +++ b/third_party/dynamics/dynamics.go @@ -78,6 +78,7 @@ func newDynamics() Dynamics { }, } d.trainInfoUdpServer = udp.NewServer(fmt.Sprintf(":%d", config.Config.Dynamics.UdpLocalPort), d.handleDynamicsTrainInfo) + d.trainInfoUdpServer.Listen() return d } diff --git a/third_party/semi_physical_train/semi_physical_train.go b/third_party/semi_physical_train/semi_physical_train.go index 3e03f02..606ecfd 100644 --- a/third_party/semi_physical_train/semi_physical_train.go +++ b/third_party/semi_physical_train/semi_physical_train.go @@ -49,6 +49,7 @@ func newSemiPhysicalTrain() SemiPhysicalTrain { trainSpeedInfoUdpClient: udp.NewClient("127.0.0.1:7777"), } s.trainControlUdpServer = udp.NewServer(fmt.Sprintf(":%d", config.Config.Dynamics.UdpLocalPort), s.handleTrainControlMsg) + s.trainControlUdpServer.Listen() return s } diff --git a/third_party/udp/udp_server.go b/third_party/udp/udp_server.go index 3947246..9566798 100644 --- a/third_party/udp/udp_server.go +++ b/third_party/udp/udp_server.go @@ -3,6 +3,7 @@ package udp import ( "log/slog" "net" + "runtime/debug" ) type UdpServer interface { @@ -54,7 +55,8 @@ func (s *server) listenAndHandle() { func (s *server) handle(b []byte) { defer func() { if err := recover(); err != nil { - slog.Error("udp server handle error", err) + slog.Error("udp server handle error", "error", err, "stack", string(debug.Stack())) + debug.PrintStack() } }() // slog.Info("udp server handle", "msg", string(b))