rbt.go 651 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package robot
  2. import (
  3. "eps/tcp/tcpserver"
  4. "fmt"
  5. "github.com/astaxie/beego"
  6. "net"
  7. "time"
  8. "wb/lg"
  9. )
  10. func EchoFunc(conn net.Conn) {
  11. ipStr := conn.RemoteAddr().String()
  12. lg.Info("ROBOT CONNECT FROM: ", ipStr)
  13. defer func() {
  14. fmt.Println("disconnected :" + ipStr)
  15. conn.Close()
  16. }()
  17. buf := make([]byte, 4096)
  18. conn.SetReadDeadline(time.Now().Add(6 * time.Second))
  19. for {
  20. if i, err := conn.Read(buf); err == nil {
  21. fmt.Print(string(buf[:i]))
  22. } else {
  23. fmt.Println(err.Error())
  24. return
  25. }
  26. }
  27. }
  28. var (
  29. RBTPort string
  30. )
  31. func init() {
  32. RBTPort = beego.AppConfig.String("rbtport")
  33. }
  34. func ServerRun() {
  35. server.Run(RBTPort, EchoFunc)
  36. }