Skip to content

Instantly share code, notes, and snippets.

@jcrubino
Created November 1, 2014 08:20
Show Gist options
  • Save jcrubino/960bb1aee9c3bd0a44c2 to your computer and use it in GitHub Desktop.
Save jcrubino/960bb1aee9c3bd0a44c2 to your computer and use it in GitHub Desktop.
// minimal example of a golang gorrilla websocket client
package main
import "github.com/gorilla/websocket"
import "net/http"
import "log"
import "os"
func main() {
conn, _, err := websocket.DefaultDialer.Dial("ws://echo.websocket.org", http.Header{})
if err != nil {
log.Println(err)
os.Exit(1)
}
msg := []byte("Hello, this is an echo test")
conn.WriteMessage(1, msg)
_, m, err := conn.ReadMessage()
if err == nil {
log.Println(string(m))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment