mirror of
https://github.com/jwetzell/showbridge-go.git
synced 2026-04-27 05:15:47 +00:00
load udp addr on init in net.udp.server
This commit is contained in:
@@ -9,8 +9,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type UDPServer struct {
|
type UDPServer struct {
|
||||||
Ip string
|
Addr *net.UDPAddr
|
||||||
Port uint16
|
|
||||||
config ModuleConfig
|
config ModuleConfig
|
||||||
router *Router
|
router *Router
|
||||||
}
|
}
|
||||||
@@ -44,7 +43,12 @@ func init() {
|
|||||||
ipString = specificIpString
|
ipString = specificIpString
|
||||||
}
|
}
|
||||||
|
|
||||||
return &UDPServer{Ip: ipString, Port: uint16(portNum), config: config}, nil
|
addr, err := net.ResolveUDPAddr("udp", fmt.Sprintf("%s:%d", ipString, uint16(portNum)))
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("error resolving UDP address: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &UDPServer{Addr: addr, config: config}, nil
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -63,13 +67,7 @@ func (us *UDPServer) RegisterRouter(router *Router) {
|
|||||||
|
|
||||||
func (us *UDPServer) Run() error {
|
func (us *UDPServer) Run() error {
|
||||||
|
|
||||||
// TODO(jwetzell): move this to init
|
listener, err := net.ListenUDP("udp", us.Addr)
|
||||||
addr, err := net.ResolveUDPAddr("udp", fmt.Sprintf("%s:%d", us.Ip, us.Port))
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("error resolving UDP address: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
listener, err := net.ListenUDP("udp", addr)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user