server needs to be before connection

This commit is contained in:
Robert Bendun 2022-12-09 16:12:33 +01:00
parent 6bbb296bb2
commit 5409aac138

View File

@ -7,6 +7,7 @@ import (
"fmt"
"time"
"strings"
"sync"
)
var clients []client
@ -15,20 +16,18 @@ var pinger chan struct{}
//export ServerInit
func ServerInit() {
// scanResult = scan()
scanResult := []string{
"10.100.5.112:8081",
"10.100.5.44:8081",
}
clients = timesync(scanResult)
pinger = make(chan struct{}, 100)
waitForConnection := sync.WaitGroup{}
waitForConnection.Add(1)
go func() {
l, err := net.Listen("tcp", ":8081")
if err != nil {
return
}
defer l.Close()
waitForConnection.Done()
for {
conn, err := l.Accept()
if err != nil {
@ -56,6 +55,12 @@ func ServerInit() {
}(conn)
}
}()
waitForConnection.Wait()
scanResult := []string{
"10.100.5.112:8081",
"10.100.5.44:8081",
}
clients = timesync(scanResult)
}
//export ServerBeginProtocol