2018-04-24 21:10:01 +00:00
|
|
|
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) {
|
|
|
|
|
2018-04-25 13:01:39 +00:00
|
|
|
startTime := time.Now().UnixNano()
|
|
|
|
|
2018-04-24 21:10:01 +00:00
|
|
|
defer sock.Close()
|
|
|
|
|
|
|
|
for {
|
|
|
|
|
2018-04-25 14:06:14 +00:00
|
|
|
req, err := request.Build(sock)
|
2018-04-24 21:10:01 +00:00
|
|
|
if err != nil {
|
2018-04-25 16:09:26 +00:00
|
|
|
fmt.Printf("STATUS CODE: %d %s\n", req.StatusCode(), req.StatusCode().Explicit())
|
2018-04-24 21:10:01 +00:00
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2018-04-25 15:28:08 +00:00
|
|
|
fmt.Printf("%v\n", req)
|
2018-04-25 13:01:39 +00:00
|
|
|
break;
|
2018-04-24 21:10:01 +00:00
|
|
|
|
|
|
|
}
|
2018-04-25 13:01:39 +00:00
|
|
|
|
|
|
|
fmt.Printf("Elapsed: %1.1f us\n", float32(time.Now().UnixNano()-startTime)/1e3)
|
2018-04-24 21:10:01 +00:00
|
|
|
}
|