Skip to content

Instantly share code, notes, and snippets.

@Gitart
Created October 30, 2016 10:05
Show Gist options
  • Save Gitart/d83fdbe02c772aeff2a1f17226c5be31 to your computer and use it in GitHub Desktop.
Save Gitart/d83fdbe02c772aeff2a1f17226c5be31 to your computer and use it in GitHub Desktop.
Websocket
package main
import (
"fmt"
"code.google.com/p/go.net/websocket"
)
const message = "Hello world"
func main() {
ws, err := websocket.Dial("ws://localhost:8082/echo", "", "http://localhost:8082")
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