mirror of https://github.com/fatedier/frp
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
630 B
44 lines
630 B
8 years ago
|
package tests
|
||
9 years ago
|
|
||
|
import (
|
||
8 years ago
|
"bufio"
|
||
9 years ago
|
"fmt"
|
||
9 years ago
|
"io"
|
||
9 years ago
|
|
||
8 years ago
|
"github.com/fatedier/frp/utils/net"
|
||
9 years ago
|
)
|
||
|
|
||
8 years ago
|
func StartEchoServer() {
|
||
|
l, err := net.ListenTcp("127.0.0.1", 10701)
|
||
9 years ago
|
if err != nil {
|
||
|
fmt.Printf("echo server listen error: %v\n", err)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
for {
|
||
|
c, err := l.Accept()
|
||
|
if err != nil {
|
||
|
fmt.Printf("echo server accept error: %v\n", err)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
go echoWorker(c)
|
||
|
}
|
||
|
}
|
||
|
|
||
8 years ago
|
func echoWorker(c net.Conn) {
|
||
|
br := bufio.NewReader(c)
|
||
9 years ago
|
for {
|
||
8 years ago
|
buf, err := br.ReadString('\n')
|
||
9 years ago
|
if err == io.EOF {
|
||
|
break
|
||
|
}
|
||
9 years ago
|
if err != nil {
|
||
|
fmt.Printf("echo server read error: %v\n", err)
|
||
|
return
|
||
|
}
|
||
|
|
||
8 years ago
|
c.Write([]byte(buf + "\n"))
|
||
9 years ago
|
}
|
||
|
}
|