Documentation
¶
Index ¶
- Constants
- Variables
- type NetConnIF
- type NetPacket
- type TCPSession
- func (s *TCPSession) Close()
- func (s *TCPSession) DirectSend(packet *NetPacket) bool
- func (s *TCPSession) DirectSendAndClose(packet *NetPacket)
- func (s *TCPSession) HandleConn(filter func(*NetPacket) bool)
- func (s *TCPSession) IsClosed() bool
- func (s *TCPSession) ReadLoop(filter func(*NetPacket) bool)
- func (s *TCPSession) RemoteAddr() net.Addr
- func (s *TCPSession) RemoteIp() net.IP
- func (s *TCPSession) Send(packet *NetPacket) bool
- func (s *TCPSession) SendLoop()
- func (s *TCPSession) SetCipher(encodeKey, decodeKey []byte) error
- func (s *TCPSession) SetParameter(readDelay, sendDelay time.Duration, maxRecvSize uint32, sendFullClose bool)
- func (s *TCPSession) SetRpmParameter(rpmLimit uint32, rpmInterval time.Duration, msg *NetPacket)
- func (s *TCPSession) TraceErrorf(format string, a ...interface{})
- func (s *TCPSession) TraceFinish(traceDefer func(*expvar.Map, int64))
- func (s *TCPSession) TracePrintf(format string, a ...interface{})
- func (s *TCPSession) TraceStart(family, title string, expvar bool)
- func (s *TCPSession) TraceStartWithStart(family, title string, expvar bool, startTime time.Time)
Constants ¶
View Source
const ( //消息报头字节数 HEAD_SIZE = 4 //消息包自增的序号 SEQ_ID_SIZE = 4 //消息号占用的字节数 MSG_ID_SIZE = 2 )
View Source
const ( SESS_KEYEXCG = 0x1 // 是否已经交换完毕KEY SESS_ENCRYPT = 0x2 // 是否可以开始加密 )
Variables ¶
View Source
var (
ServerEndian = binary.LittleEndian
)
Functions ¶
This section is empty.
Types ¶
type NetPacket ¶
type NetPacket struct {
MsgId uint16
Data []byte
Session *TCPSession
//收到该消息包的时间戳 毫秒
ReceiveTime time.Time
}
type TCPSession ¶
type TCPSession struct {
//Conn *net.TCPConn
Conn NetConnIF
IP net.IP
SendChan chan *NetPacket
ReadChan chan *NetPacket
//离线消息管道,用于外部接收连接断开的消息并处理后续
OffChan chan int64
// ID
SessionId int64
// 会话标记
Flag int32
// Declares how many times we will try to resend message
MaxSendRetries int
CloseState chanutil.DoneChan
// 对收到的包进行计数,可避免重放攻击-REPLAY-ATTACK
PacketRcvSeq uint32
//数据包发送计数器
PacketSndSeq uint32
OnLineTime int64
OffLineTime int64
EncodeKey []byte
DecodeKey []byte
// contains filtered or unexported fields
}
func NewSession ¶
func NewSession(conn NetConnIF, readChan, sendChan chan *NetPacket, offChan chan int64) (*TCPSession, error)
func (*TCPSession) Close ¶
func (s *TCPSession) Close()
func (*TCPSession) DirectSend ¶
func (s *TCPSession) DirectSend(packet *NetPacket) bool
func (*TCPSession) DirectSendAndClose ¶ added in v1.1.2
func (s *TCPSession) DirectSendAndClose(packet *NetPacket)
func (*TCPSession) HandleConn ¶
func (s *TCPSession) HandleConn(filter func(*NetPacket) bool)
func (*TCPSession) IsClosed ¶ added in v1.0.7
func (s *TCPSession) IsClosed() bool
func (*TCPSession) ReadLoop ¶
func (s *TCPSession) ReadLoop(filter func(*NetPacket) bool)
func (*TCPSession) Send ¶
func (s *TCPSession) Send(packet *NetPacket) bool
func (*TCPSession) SendLoop ¶ added in v1.0.7
func (s *TCPSession) SendLoop()
func (*TCPSession) SetCipher ¶
func (s *TCPSession) SetCipher(encodeKey, decodeKey []byte) error
RC4加密解密
func (*TCPSession) SetParameter ¶
func (s *TCPSession) SetParameter(readDelay, sendDelay time.Duration, maxRecvSize uint32, sendFullClose bool)
设置链接参数
func (*TCPSession) SetRpmParameter ¶
func (s *TCPSession) SetRpmParameter(rpmLimit uint32, rpmInterval time.Duration, msg *NetPacket)
包频率控制参数
func (*TCPSession) TraceErrorf ¶ added in v1.0.10
func (s *TCPSession) TraceErrorf(format string, a ...interface{})
func (*TCPSession) TraceFinish ¶ added in v1.0.10
func (s *TCPSession) TraceFinish(traceDefer func(*expvar.Map, int64))
func (*TCPSession) TracePrintf ¶ added in v1.0.10
func (s *TCPSession) TracePrintf(format string, a ...interface{})
func (*TCPSession) TraceStart ¶ added in v1.0.10
func (s *TCPSession) TraceStart(family, title string, expvar bool)
func (*TCPSession) TraceStartWithStart ¶ added in v1.4.10
func (s *TCPSession) TraceStartWithStart(family, title string, expvar bool, startTime time.Time)
Click to show internal directories.
Click to hide internal directories.