为什么这个 WebSocket 连接被拒绝?

huangapple go评论86阅读模式
英文:

Why is this websocket connection being refused?

问题

我尝试使用这篇博文中的slack-sample bot:https://www.opsdash.com/blog/slack-bot-in-golang.html。我已经成功创建了我的API令牌,但是无法连接到WebSocket服务器(rtm.start请求正常通过)。我收到了以下错误消息:

dial tcp 54.242.95.213:443: connectex: 由于目标计算机积极拒绝,无法建立连接

我还尝试使用一个名为Simple Web Socket Client的Chrome应用程序和一个基于网站的测试工具进行连接。两者都能正常工作,我可以建立连接并发送数据。

我在使用代理,但只有在使用golang的websocket.Dial函数时遇到问题。

有人知道为什么会出现这种情况吗?

我使用的环境是:

  • Windows 7 SP1 x64
  • Golang 1.7.1 windows/amd64

问候
Tonka

英文:

I try to use the slack-sample bot from this blogpost https://www.opsdash.com/blog/slack-bot-in-golang.html . I've successfully created my api token, but i can not connect to the websocket server (the rtm.start request passs normally). I've get the error message

> dial tcp 54.242.95.213:443: connectex: No connection could be made because the target machine actively refused it

I've also tried to connect via a chrome app called Simple Web Socket Client and via a website based one tester. Both work well, i can establish a connection and i can send data.

I'm behind a proxy, but i only have troubles with golang's websocket.Dial function.

Does anybody know why this can happen?

I use:

  • Windows 7 SP1 x64
  • Golang 1.7.1 windows/amd64

Greetings
Tonka

答案1

得分: 1

如果你正在使用gorilla/websocket,它具有使用代理的功能。根据issue 107的说明:

import "net/http"

...

var dialer = websocket.Dialer{
    Proxy: http.ProxyFromEnvironment,
}

如果你正在使用golang.org/x/net,你应该切换到gorilla/websocket。

英文:

If you are using gorilla/websocket, it has the ability to use a Proxy. From issue 107:

import "net/http"

...

var dialer = websocket.Dialer{
    Proxy: http.ProxyFromEnvironment,
}

If you are using golang.org/x/net you should switch to gorilla/websocket.

huangapple
  • 本文由 发表于 2016年9月8日 18:38:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/39388763.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定