Skip to content

Instantly share code, notes, and snippets.

@ivan3bx
Created January 9, 2016 17:24
Show Gist options
  • Save ivan3bx/ca3ebadcb0a9d6fc7de8 to your computer and use it in GitHub Desktop.
Save ivan3bx/ca3ebadcb0a9d6fc7de8 to your computer and use it in GitHub Desktop.
Simple 'echo' server with golang.org/x/net/websocket
package main
import (
"fmt"
"io"
"net/http"
"reflect"
"golang.org/x/net/websocket"
)
// Echo the data received on the WebSocket.
func EchoServer(ws *websocket.Conn) {
fmt.Println(reflect.TypeOf(ws))
io.Copy(ws, ws)
}
// This example demonstrates a trivial echo server.
func main() {
http.Handle("/", websocket.Handler(EchoServer))
err := http.ListenAndServe(":7474", nil)
if err != nil {
panic("ListenAndServe: " + err.Error())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment