Skip to content

Commit

Permalink
Added subprotocol match on client
Browse files Browse the repository at this point in the history
  • Loading branch information
DheerendraRathor committed Oct 8, 2017
1 parent 049a35a commit 28356a0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,14 @@ A simple websocket client in Golang to debug websocket server.

### Usages:
```bash
.\SimpleWsClient --addr=wss://echo.websocket.org
$ ./SimpleWsClient -help
Usage of ./SimpleWsClient:
-addr string
http service address (default "ws://echo.websocket.org")
-echoDelay uint
Delay before echoing back received message from server
-protocols string
Comma separated list of protocols to use

$ ./SimpleWsClient -addr wss://echo.websocket.org -protocols echo,chat
```
17 changes: 17 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,23 @@ func main() {
log.Fatalf("Unable to dial ws connection to agent %s with error %s\n", address, err)
}

respSubProtocol := conn.Subprotocol()
subProtocolMatch := false
if len(dialer.Subprotocols) > 0 {
for _, val := range dialer.Subprotocols {
if val == respSubProtocol {
subProtocolMatch = true
break
}
}
} else {
subProtocolMatch = respSubProtocol == ""
}

if !subProtocolMatch {
log.Fatalf("Subprotocol match failed. Server returned subprotocol: '%s'\n", respSubProtocol)
}

log.Println("Connection stabilized")
defer conn.Close()

Expand Down

0 comments on commit 28356a0

Please sign in to comment.