|
@ -15,9 +15,11 @@ import ( |
|
|
"context" |
|
|
"context" |
|
|
"fmt" |
|
|
"fmt" |
|
|
"os" |
|
|
"os" |
|
|
|
|
|
"time" |
|
|
|
|
|
|
|
|
"github.com/bboozzoo/mconnect/discovery" |
|
|
"github.com/bboozzoo/mconnect/discovery" |
|
|
"github.com/bboozzoo/mconnect/logger" |
|
|
"github.com/bboozzoo/mconnect/logger" |
|
|
|
|
|
"github.com/bboozzoo/mconnect/protocol/packet" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
var Stderr = os.Stderr |
|
|
var Stderr = os.Stderr |
|
@ -36,6 +38,29 @@ func main() { |
|
|
os.Exit(1) |
|
|
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 { |
|
|
for { |
|
|
log.Printf("receive wait") |
|
|
log.Printf("receive wait") |
|
|
d, err := l.Receive(ctx) |
|
|
d, err := l.Receive(ctx) |
|
|