diff --git a/cmd/mconnect-discover/main.go b/cmd/mconnect-discover/main.go index e8f9aa9..39b4aca 100644 --- a/cmd/mconnect-discover/main.go +++ b/cmd/mconnect-discover/main.go @@ -15,9 +15,11 @@ import ( "context" "fmt" "os" + "time" "github.com/bboozzoo/mconnect/discovery" "github.com/bboozzoo/mconnect/logger" + "github.com/bboozzoo/mconnect/protocol/packet" ) var Stderr = os.Stderr @@ -36,6 +38,29 @@ func main() { os.Exit(1) } + hostname, err := os.Hostname() + if err != nil { + fmt.Fprintf(Stderr, "error: failed to obtain hostname: %v\n", + err) + os.Exit(1) + } + + go func() { + for { + err := discovery.Announce(ctx, packet.Identity{ + DeviceId: "mconnect-" + hostname, + DeviceName: hostname, + DeviceType: "computer", + ProtocolVersion: 7, + TcpPort: 1716, + }) + if err != nil { + log.Errorf("failed to self announce: %v", err) + } + time.Sleep(5 * time.Second) + } + }() + for { log.Printf("receive wait") d, err := l.Receive(ctx)