ws/cmd/gwstester/tester.go

59 lines
914 B
Go
Raw Normal View History

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