This commit is contained in:
RamiBerm
2021-05-23 17:48:33 +03:00
parent 5cbb5a011e
commit c3e993bbc3
16 changed files with 211 additions and 84 deletions

33
shared/socket_client.go Normal file
View File

@@ -0,0 +1,33 @@
package shared
import (
"github.com/gorilla/websocket"
"time"
)
func ConnectToSocketServer(address string) (*websocket.Conn, error) {
const maxTry = 5
const sleepTime = time.Second * 2
var err error
var connection *websocket.Conn
try := 0
// Connection to server fails if client pod is up before server.
// Retries solve this issue.
for try < maxTry {
connection, _, err = websocket.DefaultDialer.Dial(address, nil)
if err != nil {
try++
// fmt.Printf("Failed connecting to websocket server: %s, (%v,%+v)\n", err, err, err)
} else {
break
}
time.Sleep(sleepTime)
}
if err != nil {
return nil, err
}
return connection, nil
}