61 lines
881 B
Go
61 lines
881 B
Go
package main
|
|
|
|
import (
|
|
"bufio"
|
|
"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 {
|
|
|
|
reader := bufio.NewReader(sock)
|
|
|
|
_, err := request.Parse(reader)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
break;
|
|
// sock.Write([]byte("coucou"))
|
|
|
|
}
|
|
|
|
fmt.Printf("Elapsed: %1.1f us\n", float32(time.Now().UnixNano()-startTime)/1e3)
|
|
}
|