derohe-proxy/proxy/client.go

47 lines
827 B
Go
Raw Normal View History

2022-05-03 22:08:36 +02:00
package proxy
import (
"crypto/tls"
"fmt"
"net/url"
"time"
"github.com/gorilla/websocket"
"github.com/lesismal/nbio/nbhttp"
)
var client *nbhttp.Client
//var connection *websocket.Conn
func Start_client(v string, w string) {
for {
u := url.URL{Scheme: "wss", Host: v, Path: "/ws/" + w}
dialer := websocket.DefaultDialer
dialer.TLSClientConfig = &tls.Config{
InsecureSkipVerify: true,
}
fmt.Println("Connect to node", v, "using wallet address", w)
connection, _, err := websocket.DefaultDialer.Dial(u.String(), nil)
if err != nil {
time.Sleep(5 * time.Second)
fmt.Println(err)
continue
}
for {
msg_type, recv_data, err := connection.ReadMessage()
if msg_type != websocket.TextMessage || err != nil {
break
} else {
go SendTemplatesToNode(recv_data)
}
}
}
}