douchao1864
douchao1864
2016-09-08 10:38

为什么此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

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • douqiu0351 douqiu0351 5年前

    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.

    点赞 评论 复制链接分享

相关推荐