Documentation ¶
Index ¶
- Constants
- func InternalIp() string
- type CloseType
- type ConnectStatusType
- type DisConnectType
- type NetworkStatus
- type Packet
- type PacketStream
- type Session
- func (s *Session) BindUserItem(item interface{})
- func (s *Session) Close(ctype CloseType)
- func (s *Session) GetBindData() interface{}
- func (s *Session) GetBindUserItem() interface{}
- func (s *Session) GetRemoteAddr() string
- func (s *Session) ID() uint64
- func (s *Session) Recv(uint16, uint16, []byte) bool
- func (s *Session) Send(mainId uint16, subId uint16, data []byte) error
- func (s *Session) SendGobMessage(mainId uint16, subId uint16, e interface{}) error
- func (s *Session) SendPbMessage(mainId uint16, subId uint16, pb proto.Message) error
- func (s *Session) SetBindData(data interface{})
- type SocketAcceptor
- func (s *SocketAcceptor) GetListenIp() string
- func (s *SocketAcceptor) GetNetworkInfo() string
- func (s *SocketAcceptor) GetSessionByID(id uint64) *Session
- func (s *SocketAcceptor) OnTimer(callback int)
- func (s *SocketAcceptor) Start(address string, keepAliveStatus NetworkStatus) error
- func (s *SocketAcceptor) Stop()
- type SocketConnector
- type SocketEvent
- type SocketEventType
- type StopWrite
- type Stream
- type TcpPacket
Constants ¶
View Source
const ( MainCmd_LogonServerIdBegin = 0 // 发送给登陆服务器的主命令开始 MainCmd_LogonServerIdEnd = 99 // 发送给登陆服务器的主命令结束 MainCmd_GateServerIdBegin = 100 // 发送给代理服务器的主命令开始 MainCmd_GateServerIdEnd = 149 // 发送给代理服务器的主命令开始 MainCmd_GameServerIdBegin = 150 // 发送给代理服务器的主命令开始 MainCmd_GameServerIdEnd = 249 // 发送给代理服务器的主命令开始 )
View Source
const ( MainGateCmd_Service = 100 // 发送给代理服务器的主命令 MainGateCmd_Network = 1000 // 网络相关主命令 )
View Source
const ( SubGateCmd_QueryServerInfo = 0 // 查询服务器信息 SubGateCmd_KeepAlive = 1 // 连接到服务器 SubGateCmd_ServerReady = 2 // 服务器就绪 SubGateCmd_ClientAlive = 3 // 客户端 )
代理服务器子命令
View Source
const ( MSG_TAG = 0x6279 XXTEA_KEY = "6279baiyikejitest" )
View Source
const ( ENCRYPT_NON = 0 ENCRYPT_XXTEA = 1 << 0 )
View Source
const ( InvliadPacketMainID = uint16(0xFFFF) InvliadPacketSubID = uint16(0xFFFF) )
View Source
const ( PacketCommandSize = 4 //MainId(uint16) + SubId(uint16) PacketHeaderSize = 5 //Msgflag(uint16) + MsgType(uint8) + MsgSize(uint16) PacketedHeadSize = 9 //Msgflag(uint16) + MsgType(uint8) + MsgSize(uint16) + MainId(uint16) + SubId(uint16) )
View Source
const (
KEEPALIVE_DETECT_TIME = 5 //心跳定时器间隔
)
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ConnectStatusType ¶
type ConnectStatusType int
const ( KeepAlive_Dead ConnectStatusType = 0 // 死亡连接 KeepAlive_Warn ConnectStatusType = 1 // 危险连接 KeepAlive_Safe ConnectStatusType = 2 // 安全连接 )
心跳状态
type DisConnectType ¶
type DisConnectType int
const ( DisConnectType_Active DisConnectType = 0 //主动断开 DisConnectType_Passive DisConnectType = 1 //被动断开 )
type NetworkStatus ¶
type NetworkStatus int
const ( NetworkStatus_Normal NetworkStatus = 0 // 正常 NetworkStatus_KeepAlive NetworkStatus = 1 // 心跳检查 )
type Packet ¶
type Packet struct { MainId uint16 // 主命令ID SubId uint16 // 子命令ID Data []byte // 数据 Ses *Session // Session }
普通封包
func (*Packet) ToByteArray ¶
func (*Packet) ToEncryptByteArray ¶
type PacketStream ¶
type PacketStream interface { Read() (*Packet, error) Write(pkt *Packet) error Close() error GetRemoteAddr() string }
封包流
func NewPacketStream ¶
func NewPacketStream(conn net.Conn, encrypt bool) PacketStream
封包流 relay模式: 在封包头有clientid信息
type Session ¶
type Session struct { OnClose func(*Session) // contains filtered or unexported fields }
func NewSession ¶
func (*Session) BindUserItem ¶
func (s *Session) BindUserItem(item interface{})
func (*Session) GetBindData ¶
func (s *Session) GetBindData() interface{}
func (*Session) GetBindUserItem ¶
func (s *Session) GetBindUserItem() interface{}
func (*Session) GetRemoteAddr ¶
func (*Session) SendGobMessage ¶
func (*Session) SendPbMessage ¶
func (*Session) SetBindData ¶
func (s *Session) SetBindData(data interface{})
type SocketAcceptor ¶
type SocketAcceptor struct {
// contains filtered or unexported fields
}
func NewAcceptor ¶
func NewAcceptor(liner *utils.LinerDispatch) *SocketAcceptor
func (*SocketAcceptor) GetListenIp ¶
func (s *SocketAcceptor) GetListenIp() string
func (*SocketAcceptor) GetNetworkInfo ¶
func (s *SocketAcceptor) GetNetworkInfo() string
func (*SocketAcceptor) GetSessionByID ¶
func (s *SocketAcceptor) GetSessionByID(id uint64) *Session
func (*SocketAcceptor) OnTimer ¶
func (s *SocketAcceptor) OnTimer(callback int)
func (*SocketAcceptor) Start ¶
func (s *SocketAcceptor) Start(address string, keepAliveStatus NetworkStatus) error
func (*SocketAcceptor) Stop ¶
func (s *SocketAcceptor) Stop()
type SocketConnector ¶
type SocketConnector struct {
// contains filtered or unexported fields
}
func NewConnector ¶
func NewConnector(liner *utils.LinerDispatch) *SocketConnector
func (*SocketConnector) Send ¶
func (s *SocketConnector) Send(mainId uint16, subId uint16, data []byte) error
发包
func (*SocketConnector) SendGobMessage ¶
func (s *SocketConnector) SendGobMessage(mainId uint16, subId uint16, e interface{}) error
func (*SocketConnector) Start ¶
func (s *SocketConnector) Start(ip string) error
func (*SocketConnector) Stop ¶
func (s *SocketConnector) Stop() bool
type SocketEvent ¶
type SocketEvent struct { EventType SocketEventType Ses *Session DisConnectReason DisConnectType }
type SocketEventType ¶
type SocketEventType int
const ( SocketEventType_Connect SocketEventType = 0 SocketEventType_DisConnect SocketEventType = 1 )
type Stream ¶
type Stream struct {
// contains filtered or unexported fields
}
func (*Stream) GetRemoteAddr ¶
Click to show internal directories.
Click to hide internal directories.