package robot import ( "eps/tcp/tcpserver" "fmt" "github.com/astaxie/beego" "net" "time" "wb/lg" ) func EchoFunc(conn net.Conn) { ipStr := conn.RemoteAddr().String() lg.Info("ROBOT CONNECT FROM: ", ipStr) defer func() { fmt.Println("disconnected :" + ipStr) conn.Close() }() buf := make([]byte, 4096) conn.SetReadDeadline(time.Now().Add(6 * time.Second)) for { if i, err := conn.Read(buf); err == nil { fmt.Print(string(buf[:i])) } else { fmt.Println(err.Error()) return } } } var ( RBTPort string ) func init() { RBTPort = beego.AppConfig.String("rbtport") } func ServerRun() { server.Run(RBTPort, EchoFunc) }