package main import ( "fmt" "net" "os" "time" "git.xdrm.io/gws/http/upgrade/request" ) 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 } fmt.Printf("+ new client\n") go manageClient(sock) } } func manageClient(sock net.Conn) { startTime := time.Now().UnixNano() defer sock.Close() for { req, err := request.Build(sock) if err != nil { fmt.Printf("STATUS CODE: %d %s\n", req.StatusCode(), req.StatusCode().Explicit()) panic(err) } fmt.Printf("%v\n", req) break; } fmt.Printf("Elapsed: %1.1f us\n", float32(time.Now().UnixNano()-startTime)/1e3) }