From 0105f5eb96ff74a84b8a4a51362e5f96e8c08b17 Mon Sep 17 00:00:00 2001 From: hzy Date: Thu, 18 Nov 2021 00:01:39 +0800 Subject: [PATCH] event-hook: connect: Support local hole port --- main.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index 2c3c49d..15dffca 100644 --- a/main.go +++ b/main.go @@ -156,9 +156,10 @@ func tcp() { } defer mode.Close() + _, port, _ := net.SplitHostPort(mode.LocalHoleAddr().String()) for { func() { - runHook("connecting", "", "", "") + runHook("connecting", "", string(port), "") protocol, err := TCPProtocol.NewMnhv1(mode, server, id) if err != nil { @@ -175,7 +176,6 @@ func tcp() { log.Info("\n\nNow you can use " + protocol.NATedAddr().String() + " to access your service") - _, port, _ := net.SplitHostPort(protocol.LocalHoleAddr().String()) addr := protocol.NATedAddr().String() runHook("success", "", port, addr) defer runHook("disconnected", "", port, addr) @@ -235,9 +235,10 @@ func udp() { } defer mode.Close() + _, port, _ := net.SplitHostPort(mode.LocalHoleAddr().String()) for { func() { - runHook("connecting", "", "", "") + runHook("connecting", "", string(port), "") protocol, err := UDPProtocol.NewMnhv1(mode, server, id) if err != nil { @@ -254,7 +255,6 @@ func udp() { log.Info("\n\nNow you can use " + protocol.NATedAddr().String() + " to access your service") - _, port, _ := net.SplitHostPort(protocol.LocalHoleAddr().String()) addr := protocol.NATedAddr().String() runHook("success", "", port, addr) defer runHook("disconnected", "", port, addr)