socket

package
v0.0.0-...-781a829 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 9, 2021 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

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

func InternalIp

func InternalIp() string

InternalIp returns an internal ip.

Types

type CloseType

type CloseType int
var (
	CloseType_UpLayer    CloseType = 0 //上层主动
	CloseType_UnderLayer CloseType = 1 //下层主动
)

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 MakePacket

func MakePacket(mainId uint16, subId uint16, data []byte, ses *Session) *Packet

func ToDecryptPacket

func ToDecryptPacket(data []byte, msgType uint8) (p *Packet, err error)

func (*Packet) ToByteArray

func (s *Packet) ToByteArray() []byte

func (*Packet) ToEncryptByteArray

func (s *Packet) ToEncryptByteArray() ([]byte, uint8)

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 NewSession(sockid uint64, tcpcon net.Conn, isEncrypt bool, liner *utils.LinerDispatch) *Session

func (*Session) BindUserItem

func (s *Session) BindUserItem(item interface{})

func (*Session) Close

func (s *Session) Close(ctype CloseType)

断开

func (*Session) GetBindData

func (s *Session) GetBindData() interface{}

func (*Session) GetBindUserItem

func (s *Session) GetBindUserItem() interface{}

func (*Session) GetRemoteAddr

func (s *Session) GetRemoteAddr() string

func (*Session) ID

func (s *Session) ID() uint64

标示ID

func (*Session) Recv

func (s *Session) Recv(uint16, uint16, []byte) bool

func (*Session) Send

func (s *Session) Send(mainId uint16, subId uint16, data []byte) error

发包

func (*Session) SendGobMessage

func (s *Session) SendGobMessage(mainId uint16, subId uint16, e interface{}) error

func (*Session) SendPbMessage

func (s *Session) SendPbMessage(mainId uint16, subId uint16, pb proto.Message) error

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 StopWrite

type StopWrite struct{}

type Stream

type Stream struct {
	// contains filtered or unexported fields
}

func (*Stream) Close

func (s *Stream) Close() error

关闭

func (*Stream) GetRemoteAddr

func (s *Stream) GetRemoteAddr() string

func (*Stream) Read

func (s *Stream) Read() (p *Packet, err error)

从socket读取1个封包,并返回

func (*Stream) Write

func (s *Stream) Write(pkt *Packet) (err error)

将一个封包发送到socket

type TcpPacket

type TcpPacket struct {
	MainId  uint16           //主命令ID
	SubId   uint16           //子命令ID
	Data    []byte           //数据
	Connect *SocketConnector //连接器
}

普通封包

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL