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