douchao1864
douchao1864
2016-09-08 10:38
浏览 485
已采纳

为什么此websocket连接被拒绝?

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

图片转代码服务由CSDN问答提供 功能建议

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

 拨号tcp 54.242.95.213:443:connectex:由于目标计算机主动拒绝连接,因此无法建立连接
    
  
 
 

我还尝试通过名为 Simple Web Socket Client 的Chrome应用和基于网站的 测试仪。 两者都很好,我可以建立连接并可以发送数据。

我在代理后面,但是我只对golang的websocket.Dial函数有麻烦。 \ n

有人知道为什么会发生这种情况吗?

我使用:
- Windows 7 SP1 x64
- Golang 1.7.1 Windows / amd64

问候 Tonka

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douqiu0351
    douqiu0351 2016-09-09 10:02
    已采纳

    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.

    点赞 评论

相关推荐