2016-05-17 19:13:37 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2016-06-06 11:43:41 +08:00
|
|
|
"io"
|
2016-05-17 19:13:37 +08:00
|
|
|
|
2016-08-11 16:10:44 +08:00
|
|
|
"github.com/fatedier/frp/src/utils/conn"
|
2016-05-17 19:13:37 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
PORT int64 = 10701
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
l, err := conn.Listen("0.0.0.0", PORT)
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func echoWorker(c *conn.Conn) {
|
|
|
|
for {
|
|
|
|
buff, err := c.ReadLine()
|
2016-06-06 11:43:41 +08:00
|
|
|
if err == io.EOF {
|
|
|
|
break
|
|
|
|
}
|
2016-05-17 19:13:37 +08:00
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("echo server read error: %v\n", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
c.Write(buff)
|
|
|
|
}
|
|
|
|
}
|