Search code examples
goproxywebsocketslack

Why is this websocket connection being refused?


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


Solution

  • 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.