doucuodan0897 2017-12-28 12:55
浏览 231
已采纳

在Go中连接到安全WebSocket时遇到问题

I'm having some troubles doing this exact connection in go-lang.

Thus far, I've done:

u := url.URL{Scheme: "wss", Host: "streamer.cryptocompare.com"}

var dialer *websocket.Dialer
conn, _, err := dialer.Dial(u.String(), nil)
l.Log(err)

msg, err := json.Marshal(Message{"SubAdd", map[string]interface{}{"subs": []string{"5~CCCAGG~BTC~USD"}}})
l.Log(err)

err = conn.WriteMessage(websocket.TextMessage, msg)
fmt.Println(err.Error())
l.Log(err)

I'm still learning about websockets, and how to use them.

Edit: This is the error, I'm getting:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x10 pc=0x718937]

goroutine 22 [running]:
github.com/gorilla/websocket.(*Conn).WriteMessage(0x0, 0x1, 0xc420248020, 0x36, 0x40, 0x0, 0x0)
    /home/avl/go/src/github.com/gorilla/websocket/conn.go:734 +0x37
main.SetupSockets(0xc420058370)
    /home/avl/Dropbox/Development/mixed/server/crypto.go:55 +0x378
created by main.main
    /home/avl/Dropbox/Development/mixed/server/main.go:21 +0x9a
exit status 2

Edit 2: Line 55 in crypto.go corresponds to this msg, err := json.Marshal(Message{"SubAdd", map[string]interface{}{"subs": []string{"5~CCCAGG~BTC~USD"}}})

  • 写回答

1条回答

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥20 大学计算机网络实验报告
      • ¥20 Oracle触发器,用户管理题目
      • ¥250 python的exchangelib 报错
      • ¥15 Oracle外部过程获取的句柄属性为空
      • ¥20 snmpv3相关提问
      • ¥20 boost电路升压频率和占空比选择
      • ¥15 找个人工智能的大佬咨询一些毕设问题
      • ¥15 需要教程:GD32F450I移植无系统lwip
      • ¥15 中文语料库检索构式 求助
      • ¥15 关于naver点击量信息