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.

48 lines
1.1 KiB

  1. package main
  2. import (
  3. "fmt"
  4. "zinx/ziface"
  5. "zinx/znet"
  6. )
  7. //ping test 自定义路由
  8. type PingRouter struct {
  9. znet.BaseRouter
  10. }
  11. //Test PreHandle
  12. func (this *PingRouter) PreHandle(request ziface.IRequest) {
  13. fmt.Println("Call Router PreHandle")
  14. _, err := request.GetConnection().GetTCPConnection().Write([]byte("before ping ....\n"))
  15. if err !=nil {
  16. fmt.Println("call back ping ping ping error")
  17. }
  18. }
  19. //Test Handle
  20. func (this *PingRouter) Handle(request ziface.IRequest) {
  21. fmt.Println("Call PingRouter Handle")
  22. _, err := request.GetConnection().GetTCPConnection().Write([]byte("ping...ping...ping\n"))
  23. if err !=nil {
  24. fmt.Println("call back ping ping ping error")
  25. }
  26. }
  27. //Test PostHandle
  28. func (this *PingRouter) PostHandle(request ziface.IRequest) {
  29. fmt.Println("Call Router PostHandle")
  30. _, err := request.GetConnection().GetTCPConnection().Write([]byte("After ping .....\n"))
  31. if err !=nil {
  32. fmt.Println("call back ping ping ping error")
  33. }
  34. }
  35. func main(){
  36. //创建一个server句柄
  37. s := znet.NewServer("[zinx V0.3]")
  38. s.AddRouter(&PingRouter{})
  39. //2 开启服务
  40. s.Serve()
  41. }