Created
September 20, 2016 13:34
-
-
Save tbillington/298e6bc9471a78f120fbe7e4c9fca66c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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