package main import ( "bufio" "fmt" "net" "os" "time" "git.xdrm.io/gws/http/upgrade/request" ) func main() { startTime := time.Now().UnixNano() /* (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) } fmt.Printf("Elapsed: %d ns\n", time.Now().UnixNano()-startTime) } func manageClient(sock net.Conn) { defer sock.Close() for { reader := bufio.NewReader(sock) _, err := request.Parse(reader) if err != nil { panic(err) } sock.Write([]byte("coucou")) } }