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.

34 lines
900 B

4 years ago
4 years ago
  1. package ziface
  2. import (
  3. "context"
  4. "net"
  5. )
  6. //定义连接接口
  7. type IConnection interface {
  8. //启动连接,让当前连接开始工作
  9. Start()
  10. //停止连接,结束当前连接状态M
  11. Stop()
  12. //返回ctx,用于用户自定义的go程获取连接退出状态
  13. Context() context.Context
  14. //从当前连接获取原始的socket TCPConn
  15. GetTCPConnection() *net.TCPConn
  16. //获取当前连接ID
  17. GetConnID() uint32
  18. //获取远程客户端地址信息
  19. RemoteAddr() net.Addr
  20. //直接将Message数据发送数据给远程的TCP客户端(无缓冲)
  21. SendMsg(msgID uint32, data []byte) error
  22. //直接将Message数据发送给远程的TCP客户端(有缓冲)
  23. SendBuffMsg(msgID uint32, data []byte) error
  24. //设置链接属性
  25. SetProperty(key string, value interface{})
  26. //获取链接属性
  27. GetProperty(key string) (interface{}, error)
  28. //移除链接属性
  29. RemoveProperty(key string)
  30. }