mirror of
https://github.com/bolucat/Archive.git
synced 2025-12-24 13:28:37 +08:00
Update On Thu May 30 20:33:30 CEST 2024
This commit is contained in:
@@ -1,17 +1,26 @@
|
||||
package main
|
||||
|
||||
import "github.com/Ehco1996/ehco/test/echo"
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/Ehco1996/ehco/test/echo"
|
||||
)
|
||||
|
||||
func main() {
|
||||
msg := []byte("hello")
|
||||
|
||||
echoServerAddr := "127.0.0.1:2333"
|
||||
println("real echo server at:", echoServerAddr)
|
||||
|
||||
// start ehco real server
|
||||
// go run cmd/ehco/main.go -l 0.0.0.0:2234 -r 0.0.0.0:2333
|
||||
|
||||
relayAddr := "127.0.0.1:2234"
|
||||
println("real echo server at:", echoServerAddr, "relay addr:", relayAddr)
|
||||
|
||||
ret := echo.SendTcpMsg(msg, relayAddr)
|
||||
println(string(ret))
|
||||
if string(ret) != "hello" {
|
||||
panic("relay short failed")
|
||||
}
|
||||
println("test short conn success, hello sended and received")
|
||||
|
||||
if err := echo.EchoTcpMsgLong(msg, time.Second, relayAddr); err != nil {
|
||||
panic("relay long failed:" + err.Error())
|
||||
}
|
||||
println("test long conn success")
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ func echo(conn net.Conn) {
|
||||
logger.Error(err.Error())
|
||||
return
|
||||
}
|
||||
println("echo server receive", string(buf[:i]))
|
||||
_, err = conn.Write(buf[:i])
|
||||
if err != nil {
|
||||
logger.Error(err.Error())
|
||||
@@ -135,7 +136,7 @@ func EchoTcpMsgLong(msg []byte, sleepTime time.Duration, address string) error {
|
||||
return err
|
||||
}
|
||||
if string(buf[:n]) != string(msg) {
|
||||
return fmt.Errorf("msg not equal")
|
||||
return fmt.Errorf("msg not equal at %d send:%s receive:%s n:%d", i, msg, buf[:n], n)
|
||||
}
|
||||
// to fake a long connection
|
||||
time.Sleep(sleepTime)
|
||||
|
||||
16
echo/test/echo/ws.json
Normal file
16
echo/test/echo/ws.json
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"relay_configs": [
|
||||
{
|
||||
"listen": "127.0.0.1:2234",
|
||||
"listen_type": "raw",
|
||||
"transport_type": "ws",
|
||||
"tcp_remotes": ["ws://0.0.0.0:2443"]
|
||||
},
|
||||
{
|
||||
"listen": "127.0.0.1:2443",
|
||||
"listen_type": "ws",
|
||||
"transport_type": "raw",
|
||||
"tcp_remotes": ["127.0.0.1:2333"]
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user