Documentation ¶
Index ¶
- Constants
- Variables
- type TCPNetwork
- type TcpConn
- func (c *TcpConn) Close()
- func (c *TcpConn) CloseSocket()
- func (c *TcpConn) GetNetConn() net.Conn
- func (c *TcpConn) GetUserData() interface{}
- func (c *TcpConn) InitData()
- func (c *TcpConn) RemoteAddr() string
- func (c *TcpConn) RemoveData()
- func (c *TcpConn) Send(data []byte) int
- func (c *TcpConn) SendDirect(data []byte) int
- func (c *TcpConn) SendPak(val interface{}) int
- func (c *TcpConn) SendPakDirect(val interface{}) int
- func (c *TcpConn) SetReadTime(d time.Duration)
- func (c *TcpConn) SetUserData(user interface{})
- func (c *TcpConn) SetWriteTime(w time.Duration)
Constants ¶
View Source
const ( ReadWaitPing = 65 * time.Second WriteTicker = 45 * time.Second )
View Source
const ( RMStream = iota // 使用流算法读写数据包 RMReadFull // 使用固定算法读写数据包 固定算法 包头4字节为固定长度,其余位置为数据包payload RMStringLine // 通过使用\n来进行文本拆分 )
Variables ¶
View Source
var (
HandlerProc = 1
)
Functions ¶
This section is empty.
Types ¶
type TCPNetwork ¶
type TCPNetwork struct { NetCM *cm.ConnManager RecvMode int SendRetry int UseHeaderLen bool // 是否自动附加头部4字节(RMFULL模式下强制附加) /// 所有的callBack函数 // 创建用户DATA CreateUserData func() interface{} // 通知连接 OnAccept func(conn *TcpConn) // 数据包进入 OnHandler func(conn *TcpConn, ownerPak []byte) // 连接关闭 OnClose func(conn *TcpConn) // 连接成功 OnConnected func(conn *TcpConn) MainProc func() // 简易主处理函数 // 打包以及加密行为 Package func(val interface{}) (data []byte, err error) Unpackage func(conn *TcpConn, spak *stream.BufferIO) (data [][]byte, err error) // 输出panic数据 Panic func(conn *TcpConn, src string) Encrypt func(data, key []byte) []byte Decrypt func(data, key []byte) []byte // ping,pong CALL SendPing func(conn *TcpConn) SendPong func(conn *TcpConn, ping []byte) bool // contains filtered or unexported fields }
func NewEmptyTcp ¶
func NewEmptyTcp(mode int) *TCPNetwork
func NewTcpServer ¶
func NewTcpServer(mode int, addr string) (tcp *TCPNetwork, err error)
/////////////////////////// 创建网络服务器
func (*TCPNetwork) Dial ¶
func (c *TCPNetwork) Dial(addr string, UserData interface{}) (conn *TcpConn, err error)
func (*TCPNetwork) RemoveSession ¶
func (c *TCPNetwork) RemoveSession(sessionId string)
////////////////////////// 成员函数
func (*TCPNetwork) Runnable ¶
func (c *TCPNetwork) Runnable()
type TcpConn ¶
type TcpConn struct { cm.Conn TConn net.Conn // tcp连接 UserData interface{} // 用户对象 LastPing time.Time CryptKey []byte IsClosed int32 ReadTime time.Duration WriteTime time.Duration // contains filtered or unexported fields }
func NewDial ¶
func NewDial(tn *TCPNetwork, addr string, UData interface{}) (conn *TcpConn, err error)
func (*TcpConn) CloseSocket ¶
func (c *TcpConn) CloseSocket()
func (*TcpConn) GetNetConn ¶
func (*TcpConn) GetUserData ¶
func (c *TcpConn) GetUserData() interface{}
func (*TcpConn) RemoteAddr ¶
func (*TcpConn) RemoveData ¶
func (c *TcpConn) RemoveData()
func (*TcpConn) SendDirect ¶
func (*TcpConn) SendPakDirect ¶
func (*TcpConn) SetReadTime ¶
//////////////////////////////////////////// 成员函数
func (*TcpConn) SetUserData ¶
func (c *TcpConn) SetUserData(user interface{})
func (*TcpConn) SetWriteTime ¶
Click to show internal directories.
Click to hide internal directories.