From c1a98483a499f4fdaf4b0d461fdd359035ca4e0d Mon Sep 17 00:00:00 2001 From: Joel Wetzell Date: Wed, 3 Dec 2025 00:18:17 -0600 Subject: [PATCH] add optional ip setting for net.tcp.server --- tcp-server.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/tcp-server.go b/tcp-server.go index 5049941..dd52ffc 100644 --- a/tcp-server.go +++ b/tcp-server.go @@ -12,6 +12,7 @@ import ( type TCPServer struct { config ModuleConfig + Ip string Port uint16 framingMethod string router *Router @@ -46,7 +47,20 @@ func init() { return nil, fmt.Errorf("tcp framing method must be a string") } - return &TCPServer{framingMethod: framingMethodString, Port: uint16(portNum), config: config, quit: make(chan interface{})}, nil + ipString := "0.0.0.0" + + ip, ok := params["ip"] + if ok { + + specificIpString, ok := ip.(string) + + if !ok { + return nil, fmt.Errorf("tcp ip method must be a string") + } + ipString = specificIpString + } + + return &TCPServer{framingMethod: framingMethodString, Port: uint16(portNum), Ip: ipString, config: config, quit: make(chan interface{})}, nil }, }) } @@ -116,7 +130,7 @@ ClientRead: } func (ts *TCPServer) Run() error { - listener, err := net.Listen("tcp", fmt.Sprintf(":%d", ts.Port)) + listener, err := net.Listen("tcp", fmt.Sprintf("%s:%d", ts.Ip, ts.Port)) if err != nil { return err }