Skip to content

Instantly share code, notes, and snippets.

@moderation
Created April 24, 2011 20:07
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save moderation/939839 to your computer and use it in GitHub Desktop.
Save moderation/939839 to your computer and use it in GitHub Desktop.
golang websockets client
package main
import (
"fmt"
"websocket"
)
// const message = "A message"
func main() {
ws, err := websocket.Dial("ws://localhost:8000/", "", "http://localhost:8000/")
ws.SetTimeout(1000000000e6)
ws.SetReadTimeout(1000000000e6)
if err != nil {
panic(err)
}
// if _, err := ws.Write([]byte(message)); err != nil {
// panic(err)
// }
var resp = make([]byte, 4096)
n, err := ws.Read(resp)
if err != nil {
panic(err)
}
fmt.Println("Received:", string(resp[0:n]))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment