英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论