Skip to content

Instantly share code, notes, and snippets.

@stesla
Created February 17, 2012 16:16
Show Gist options
  • Save stesla/1854167 to your computer and use it in GitHub Desktop.
Save stesla/1854167 to your computer and use it in GitHub Desktop.
A simple websocket echo server
package main
import (
"net/http"
"io"
"code.google.com/p/go.net/websocket"
)
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
io.WriteString(w, "Hello, World!\n")
})
http.Handle("/echo", websocket.Handler(func(ws *websocket.Conn) {
for {
var msg string
websocket.Message.Receive(ws, &msg)
websocket.Message.Send(ws, "ECHO: " + msg)
}
}))
http.ListenAndServe(":8080", nil);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment