Documentation
¶
Overview ¶
通讯协议处理,主要处理封包和解包的过程
Index ¶
- Constants
- Variables
- func BytesToInt(b []byte) int32
- func BytesTouInt32(b []byte) uint32
- func CheckECC(data []byte) uint32
- func DoPacket(message []byte) []byte
- func GetUniq() int
- func IntToBytes(n int32) []byte
- func UInt32ToBytes(n uint32) []byte
- func Unpack(buffer []byte, readerChannel chan Packet) (leftbuffer []byte)
- type Config
- type Conn
- func (c *Conn) AsyncReadPacket(timeout time.Duration) (Packet, error)
- func (c *Conn) AsyncWritePacket(p Packet, timeout time.Duration) error
- func (c *Conn) Close()
- func (c *Conn) Do()
- func (c *Conn) GetExtraData() string
- func (c *Conn) GetRawConn() *net.TCPConn
- func (c *Conn) IsClosed() bool
- func (c *Conn) PutExtraData(data string)
- type ConnCallback
- type ConnManager
- type Packet
- type Protocol
- type Server
- type StreamPacket
Constants ¶
View Source
const ( ConstHeader = "SeanCommu" ConstHeaderLength int32 = 9 ConstSaveDataLength int32 = 4 ConstEndCheckECCLength int32 = 4 TempToken = "e675d1b7e23c8a9ca3a3479d6cf29232" )
View Source
const ( ConstPackNoHeader = 0 ConstPackHasHeader = 1 )
Variables ¶
View Source
var ( ErrConnClosing = errors.New("use of closed network connection") ErrWriteBlocking = errors.New("write packet was blocking") ErrReadBlocking = errors.New("read packet was blocking") )
Error type
Functions ¶
Types ¶
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
Conn exposes a set of callbacks for the various events that occur on a connection
func (*Conn) AsyncReadPacket ¶
AsyncReadPacket async reads a packet, this method will never block
func (*Conn) AsyncWritePacket ¶
AsyncWritePacket async writes a packet, this method will never block
func (*Conn) GetExtraData ¶
GetExtraData gets the extra data from the Conn
func (*Conn) GetRawConn ¶
GetRawConn returns the raw net.TCPConn from the Conn
func (*Conn) PutExtraData ¶
PutExtraData puts the extra data with the Conn
type ConnCallback ¶
type ConnCallback interface { // OnConnect is called when the connection was accepted, // If the return value of false is closed OnConnect(*Conn) bool // OnMessage is called when the connection receives a packet, // If the return value of false is closed OnMessage(*Conn, Packet) bool // OnClose is called when the connection closed OnClose(*Conn) }
ConnCallback is an interface of methods that are used as callbacks on a connection
type ConnManager ¶
type ConnManager struct {
// contains filtered or unexported fields
}
func NewConnManager ¶
func NewConnManager() *ConnManager
func (*ConnManager) AddConn ¶
func (m *ConnManager) AddConn(id string, conn *Conn)
func (*ConnManager) Broadcast ¶
func (m *ConnManager) Broadcast(packet Packet)
func (*ConnManager) DelConn ¶
func (m *ConnManager) DelConn(id string)
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func NewServer ¶
func NewServer(config *Config, callback ConnCallback, protocol Protocol) *Server
NewServer creates a server
type StreamPacket ¶
type StreamPacket struct {
// contains filtered or unexported fields
}
func NewStreamPacket ¶
func NewStreamPacket(buff []byte) *StreamPacket
func (*StreamPacket) GetBody ¶
func (this *StreamPacket) GetBody() []byte
func (*StreamPacket) GetLength ¶
func (this *StreamPacket) GetLength() uint32
func (*StreamPacket) Serialize ¶
func (this *StreamPacket) Serialize() []byte
Click to show internal directories.
Click to hide internal directories.