| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- package conn
- import (
- "fmt"
- "net"
- )
- // 消息类型
- type MsgType byte
- const (
- PingMsg MsgType = iota
- RequestMsg
- ResponseMsg
- ProxyConnectMsg
- ProxyResultMsg
- )
- func (t MsgType) String() string {
- switch t {
- case PingMsg:
- return "PingMsg"
- case RequestMsg:
- return "RequestMsg"
- case ResponseMsg:
- return "ResponseMsg"
- case ProxyConnectMsg:
- return "ProxyConnectMsg"
- case ProxyResultMsg:
- return "ProxyResultMsg"
- default:
- return fmt.Sprintf("Unknown MsgType (%d)", t)
- }
- }
- // 连接接口,代表一个原始的连接
- type Connect interface {
- ReadAuthInfo() (proto string, version uint8, channel string, auth []byte, err error)
- ReadMessage(deadline int) (msgType MsgType, id uint16, cmd string, state uint8, data []byte, err error)
- ReadRawPackage(deadline int) (buf []byte, recycle bool, err error)
- WriteRawPackage(raw []byte, recycle bool) (err error)
- WriteAuthInfo(channel string, auth []byte) (err error)
- WriteRequest(id uint16, cmd string, data []byte) error
- WriteResponse(id uint16, state uint8, data []byte) error
- WritePing(id uint16) error
- RemoteIP() net.IP
- LocalIP() net.IP
- Close() error
- }
- // 服务请求连接
- type ServerConnectFunc func(conn Connect)
|