conn.go 751 B

12345678910111213141516171819202122232425262728293031
  1. package conn
  2. import (
  3. "net"
  4. )
  5. // 消息类型
  6. type MsgType byte
  7. const (
  8. PingMsg MsgType = iota
  9. RequestMsg
  10. ResponseMsg
  11. )
  12. // 连接接口,代表一个原始的连接
  13. type Connect interface {
  14. WriteAuthInfo(channel string, auth []byte) (err error)
  15. ReadAuthInfo() (proto string, version uint8, channel string, auth []byte, err error)
  16. // WriteChannel(data []byte) error
  17. WriteRequest(id uint16, cmd string, data []byte) error
  18. WriteResponse(id uint16, state uint8, data []byte) error
  19. WritePing(id uint16) error
  20. ReadMessage(deadline int) (msgType MsgType, id uint16, cmd string, state uint8, data []byte, err error)
  21. RemoteAddr() net.Addr
  22. LocalAddr() net.Addr
  23. Close() error
  24. }
  25. // 服务请求连接
  26. type ServerConnectFunc func(conn Connect)