mirror of
https://github.com/ICKelin/opennotr.git
synced 2025-09-26 20:01:13 +08:00
test: add websocket test
This commit is contained in:
3
go.mod
3
go.mod
@@ -19,13 +19,14 @@ require (
|
||||
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect
|
||||
github.com/google/btree v1.0.0 // indirect
|
||||
github.com/google/uuid v1.1.1 // indirect
|
||||
github.com/gorilla/websocket v1.4.0 // indirect
|
||||
github.com/gorilla/websocket v1.4.0
|
||||
github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190118093823-f849b5445de4 // indirect
|
||||
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
|
||||
github.com/grpc-ecosystem/grpc-gateway v1.9.5 // indirect
|
||||
github.com/inetaf/tcpproxy v0.0.0-20200125044825-b6bb9b5b8252
|
||||
github.com/jonboulle/clockwork v0.1.0 // indirect
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect
|
||||
github.com/siddontang/go v0.0.0-20170517070808-cb568a3e5cc0
|
||||
github.com/soheilhy/cmux v0.1.4 // indirect
|
||||
github.com/songgao/water v0.0.0-20200317203138-2b4b6d7c09d8
|
||||
github.com/stretchr/testify v1.5.1 // indirect
|
||||
|
1
go.sum
1
go.sum
@@ -168,6 +168,7 @@ github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6So
|
||||
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
|
||||
github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644 h1:X+yvsM2yrEktyI+b2qND5gpH8YhURn0k8OCaeRnkINo=
|
||||
github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644/go.mod h1:nkxAfR/5quYxwPZhyDxgasBMnRtBZd0FCEpawpjMUFg=
|
||||
github.com/siddontang/go v0.0.0-20170517070808-cb568a3e5cc0 h1:QIF48X1cihydXibm+4wfAc0r/qyPyuFiPFRNphdMpEE=
|
||||
github.com/siddontang/go v0.0.0-20170517070808-cb568a3e5cc0/go.mod h1:3yhqj7WBBfRhbBlzyOC3gUxftwsU0u8gqevxwIHQpMw=
|
||||
github.com/siddontang/goredis v0.0.0-20150324035039-760763f78400/go.mod h1:DDcKzU3qCuvj/tPnimWSsZZzvk9qvkvrIL5naVBPh5s=
|
||||
github.com/siddontang/rdb v0.0.0-20150307021120-fc89ed2e418d/go.mod h1:AMEsy7v5z92TR1JKMkLLoaOQk++LVnOKL3ScbJ8GNGA=
|
||||
|
29
opennotrd/test/websocket/wsclient.go
Normal file
29
opennotrd/test/websocket/wsclient.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
)
|
||||
|
||||
func main() {
|
||||
raddr := flag.String("r", "", "remote address")
|
||||
flag.Parse()
|
||||
buf := make([]byte, 1024)
|
||||
for i := 0; i < 100; i++ {
|
||||
beg := time.Now()
|
||||
conn, _, err := websocket.DefaultDialer.Dial(*raddr, nil)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
defer conn.Close()
|
||||
conn.WriteMessage(websocket.BinaryMessage, buf)
|
||||
conn.ReadMessage()
|
||||
fmt.Printf("echo websocket packet %d rtt %dms\n", i+1, time.Now().Sub(beg).Milliseconds())
|
||||
time.Sleep(time.Second * 1)
|
||||
}
|
||||
}
|
31
opennotrd/test/websocket/wsserver.go
Normal file
31
opennotrd/test/websocket/wsserver.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/siddontang/go/websocket"
|
||||
)
|
||||
|
||||
func main() {
|
||||
localAddress := flag.String("l", "", "local address")
|
||||
flag.Parse()
|
||||
|
||||
http.HandleFunc("/ws", func(w http.ResponseWriter, r *http.Request) {
|
||||
conn, err := websocket.Upgrade(w, r, r.Header)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
msgType, msg, err := conn.Read()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
conn.WriteMessage(msgType, msg)
|
||||
})
|
||||
http.ListenAndServe(*localAddress, nil)
|
||||
}
|
Reference in New Issue
Block a user