Browse Source

cmd/mconnect-discover: self announce

Signed-off-by: Maciek Borzecki <maciek.borzecki@gmail.com>
bboozzoo/golang
Maciek Borzecki 7 years ago
parent
commit
3ca4c43a44
1 changed files with 25 additions and 0 deletions
  1. +25
    -0
      cmd/mconnect-discover/main.go

+ 25
- 0
cmd/mconnect-discover/main.go View File

@ -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)


Loading…
Cancel
Save