package main import ( "git.xdrm.io/gws/upgrader" "fmt" "net" "os" "time" ) func main() { /* (1) Create listening socket ---------------------------------------------------------*/ /* (1) Create socket */ lsock, err := net.Listen("tcp", ":4444") if err != nil { panic(err) } /* (2) Accept clients */ for { sock, err := lsock.Accept() if err != nil { os.Stderr.WriteString(fmt.Sprintf("Connection error: %s\n", err)) return } go manageClient(sock) } } func manageClient(sock net.Conn) { startTime := time.Now().UnixNano() defer sock.Close() for { fmt.Printf("+ new client\n") fmt.Printf(" + upgrade\n") err := upgrader.Upgrade(sock) if err != nil { fmt.Printf(" + error: %s\n", err) return } fmt.Printf(" + 2-way exchange\n") break; } fmt.Printf("+ elapsed: %1.1f us\n", float32(time.Now().UnixNano()-startTime)/1e3) }