golang的wsClient连接chat.workerman.net:7272
出现的问题
2023/06/10 11:41:49 websocket.Dial ws://chat.workerman.net:7272/: bad protocol version
package business
import (
"golang.org/x/net/websocket"
"log"
"net"
"net/url"
"testing"
"time"
)
func TestBusiness_InnerOnWorkerStart(t *testing.T) {
// 设置WebSocket连接的地址和origin
wsURL := &url.URL{
Scheme: "ws",
Host: "chat.workerman.net:7272",
}
// 创建WebSocket配置
wsConfig := &websocket.Config{
Location: wsURL,
Dialer: &net.Dialer{
Timeout: 10 * time.Second,
},
Origin: &url.URL{Scheme: "http", Host: "chat.workerman.net"},
}
// 连接WebSocket服务器
wsConn, err := websocket.DialConfig(wsConfig)
if err != nil {
log.Fatalln(err)
}
// 发送和接收数据
// ...
// 关闭WebSocket连接
wsConn.Close()
}
ws://chat.workermnan.net:7272/:
这个末尾:,是error字段的,不是生成的地址错误.
fmt.println("websocket.Dial {addr}: bad protocol verision")
在
websocket.Config
里加Version: websocket.ProtocolVersionHybi13
const (
ProtocolVersionHybi13 = 13
ProtocolVersionHybi = ProtocolVersionHybi13
)
好像也就这一个版本号可选
嗯,workerman 也是写死了 13 的