Skip to content

Instantly share code, notes, and snippets.

@tbillington
Created September 20, 2016 13:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tbillington/298e6bc9471a78f120fbe7e4c9fca66c to your computer and use it in GitHub Desktop.
Save tbillington/298e6bc9471a78f120fbe7e4c9fca66c to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"net/http"
"golang.org/x/net/websocket"
)
var i int = 0
func handlerGen(incoming chan interface{}) func(*websocket.Conn) {
return func(ws *websocket.Conn) {
fmt.Println(i)
i++
// fmt.Printf("New connection from %s %s\n", ws.RemoteAddr().Network(), ws.RemoteAddr().String())
}
}
func main() {
fmt.Println("Server starting")
var incoming = make(chan interface{}, 100)
http.Handle("/", websocket.Handler(handlerGen(incoming)))
err := http.ListenAndServe(":12345", 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