Documentation ¶
Index ¶
- Variables
- func CheckTimeout(err error) bool
- func GetDefaultPackageHeadLen() int
- type ClientBase
- func (c *ClientBase) CloseTimeout()
- func (c *ClientBase) CloseWithErr(err error, stack []byte, check bool)
- func (c *ClientBase) Error() string
- func (c *ClientBase) Init(ddb DataDecodeBase, ttl, RTtl time.Duration, onSocket OnSocket, con Conn, ...)
- func (c *ClientBase) IsClosedByPeer() bool
- func (c *ClientBase) Reactor()
- func (c *ClientBase) SafeClose(byLocalNotRemote bool)
- func (c *ClientBase) Send(buf []byte) bool
- func (c *ClientBase) SessionId() uint64
- func (c *ClientBase) Stack() []byte
- func (c *ClientBase) UnionId() string
- type ClientSocket
- func (c *ClientSocket) Close() error
- func (c *ClientSocket) Connect(addr string, ttl time.Duration, OnSocket OnSocket, ddb DataDecodeBase) error
- func (c *ClientSocket) ConnectHostPort(host string, port uint16, Ttl time.Duration, OnSocket OnSocket, ...) error
- func (c *ClientSocket) LocalAddr() net.Addr
- func (c *ClientSocket) ReConnect(addr string) error
- func (c *ClientSocket) RemoteAddr() net.Addr
- func (c *ClientSocket) SetConnect(conn net.Conn)
- type ClientWSocket
- func (c *ClientWSocket) Close() error
- func (c *ClientWSocket) Connect(addr string, msgType int, ttl time.Duration, OnSocket OnSocket, ...) error
- func (c *ClientWSocket) LocalAddr() net.Addr
- func (c *ClientWSocket) ReConnect(addr string) error
- func (c *ClientWSocket) RemoteAddr() net.Addr
- func (c *ClientWSocket) SetConnect(conn *websocket.Conn)
- type Conn
- type Context
- func (c *Context) Deadline() (deadline time.Time, ok bool)
- func (c *Context) Done() <-chan struct{}
- func (c *Context) Err() error
- func (c *Context) Get(key string) (value any, exists bool)
- func (c *Context) GetBool(key string) (b bool)
- func (c *Context) GetFloat64(key string) (f64 float64)
- func (c *Context) GetInt(key string) (i int)
- func (c *Context) GetInt64(key string) (i64 int64)
- func (c *Context) GetString(key string) (s string)
- func (c *Context) GetUint(key string) (ui uint)
- func (c *Context) GetUint64(key string) (ui64 uint64)
- func (c *Context) SessionId() uint64
- func (c *Context) Set(key string, value any)
- func (c *Context) String() string
- func (c *Context) Value(key any) any
- type DataDecodeBase
- type DataDecodeBinaryBigEnd
- type DataDecodeText
- type OnSocket
- type OnSocketServer
- type ServerSocket
- func (s *ServerSocket) Listen() error
- func (s *ServerSocket) OnClose(conn Conn, byLocalNotRemote bool)
- func (s *ServerSocket) OnConnect(conn Conn)
- func (s *ServerSocket) OnNetErr(conn Conn)
- func (s *ServerSocket) OnRecvMsg(conn Conn, buf []byte) bool
- func (s *ServerSocket) OnTimeout(conn Conn)
- func (s *ServerSocket) Shutdown()
- type StackError
- type Status
- type StatusConnServer
- type StatusNO
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func CheckTimeout ¶
func GetDefaultPackageHeadLen ¶
func GetDefaultPackageHeadLen() int
Types ¶
type ClientBase ¶
type ClientBase struct { Status Status //sendUse sync.Map SessionIdU uint64 UnionIdStr string // contains filtered or unexported fields }
func (*ClientBase) CloseTimeout ¶
func (c *ClientBase) CloseTimeout()
func (*ClientBase) CloseWithErr ¶
func (c *ClientBase) CloseWithErr(err error, stack []byte, check bool)
func (*ClientBase) Error ¶
func (c *ClientBase) Error() string
func (*ClientBase) Init ¶
func (c *ClientBase) Init(ddb DataDecodeBase, ttl, RTtl time.Duration, onSocket OnSocket, con Conn, socket iSocket)
func (*ClientBase) IsClosedByPeer ¶
func (c *ClientBase) IsClosedByPeer() bool
func (*ClientBase) Reactor ¶
func (c *ClientBase) Reactor()
func (*ClientBase) SafeClose ¶
func (c *ClientBase) SafeClose(byLocalNotRemote bool)
func (*ClientBase) Send ¶
func (c *ClientBase) Send(buf []byte) bool
func (*ClientBase) SessionId ¶
func (c *ClientBase) SessionId() uint64
func (*ClientBase) Stack ¶
func (c *ClientBase) Stack() []byte
func (*ClientBase) UnionId ¶
func (c *ClientBase) UnionId() string
type ClientSocket ¶
type ClientSocket struct { ClientBase // contains filtered or unexported fields }
*********ClientSocket
func Agent ¶
func Agent(conn net.Conn, ttl time.Duration, rTtl time.Duration, OnSocket OnSocket, ddb DataDecodeBase) *ClientSocket
func (*ClientSocket) Close ¶
func (c *ClientSocket) Close() error
func (*ClientSocket) Connect ¶
func (c *ClientSocket) Connect(addr string, ttl time.Duration, OnSocket OnSocket, ddb DataDecodeBase) error
func (*ClientSocket) ConnectHostPort ¶
func (c *ClientSocket) ConnectHostPort(host string, port uint16, Ttl time.Duration, OnSocket OnSocket, ddb DataDecodeBase) error
func (*ClientSocket) LocalAddr ¶
func (c *ClientSocket) LocalAddr() net.Addr
LocalAddr returns the local network address.
func (*ClientSocket) ReConnect ¶
func (c *ClientSocket) ReConnect(addr string) error
func (*ClientSocket) RemoteAddr ¶
func (c *ClientSocket) RemoteAddr() net.Addr
RemoteAddr returns the remote network address.
func (*ClientSocket) SetConnect ¶ added in v0.0.19
func (c *ClientSocket) SetConnect(conn net.Conn)
支持复用
type ClientWSocket ¶
type ClientWSocket struct { ClientBase // contains filtered or unexported fields }
func WebAgent ¶
func WebAgent(conn *websocket.Conn, msgType int, ttl time.Duration, rTtl time.Duration, OnSocket OnSocket, ddb DataDecodeBase) *ClientWSocket
@msgType TextMessage or BinaryMessage
func (*ClientWSocket) Close ¶
func (c *ClientWSocket) Close() error
func (*ClientWSocket) Connect ¶
func (c *ClientWSocket) Connect(addr string, msgType int, ttl time.Duration, OnSocket OnSocket, ddb DataDecodeBase) error
@msgType TextMessage or BinaryMessage
func (*ClientWSocket) LocalAddr ¶
func (c *ClientWSocket) LocalAddr() net.Addr
LocalAddr returns the local network address.
func (*ClientWSocket) ReConnect ¶
func (c *ClientWSocket) ReConnect(addr string) error
func (*ClientWSocket) RemoteAddr ¶
func (c *ClientWSocket) RemoteAddr() net.Addr
RemoteAddr returns the remote network address.
func (*ClientWSocket) SetConnect ¶ added in v0.0.19
func (c *ClientWSocket) SetConnect(conn *websocket.Conn)
支持复用
type Conn ¶
type Conn interface { //获取最近的错误 error //安全关闭连接 //@param byLocalNotRemote 是否是本地主动本地断开;true:对服务器而言就是服务器把客户端断开,对客户端而言就是客户端主动断服务器 SafeClose(byLocalNotRemote bool) // 封装发送buffer Send(buf []byte) bool //是否是被对方关闭了连接 IsClosedByPeer() bool //获取最近的调用堆栈,如果有的话 Stack() []byte //本地地址 LocalAddr() net.Addr //对方地址 RemoteAddr() net.Addr //当前服务器中的唯一ID SessionId() uint64 //唯一ID,多个服务器的话可能 SessionId会一样,但是UnionId肯定不一样 UnionId() string }
* 对外宣称对象
type Context ¶
type Context struct { Con Conn //连接对象 OnSocket OnSocket //对socket的监听 // contains filtered or unexported fields }
func (*Context) GetFloat64 ¶
GetFloat64 returns the value associated with the key as a float64.
type DataDecodeBase ¶
type DataDecodeBase interface { //包解析 =》 包长+包内容 =》整个包的长度 = 包长+包内容长度 //返回包长的长度 GetPackageHeadLen() int //返回包内容的长度 GetPackageLen([]byte) int }
* Socket 数据解析
type DataDecodeBinaryBigEnd ¶
type DataDecodeBinaryBigEnd struct { }
二进制大端包 => 2字节包长+包内容
func (*DataDecodeBinaryBigEnd) GetPackageHeadLen ¶
func (d *DataDecodeBinaryBigEnd) GetPackageHeadLen() int
func (*DataDecodeBinaryBigEnd) GetPackageLen ¶
func (d *DataDecodeBinaryBigEnd) GetPackageLen(buf []byte) int
type DataDecodeText ¶
type DataDecodeText struct { }
文本解析 => 没有长度的概念+包内容
func (*DataDecodeText) GetPackageHeadLen ¶
func (d *DataDecodeText) GetPackageHeadLen() int
func (*DataDecodeText) GetPackageLen ¶
func (d *DataDecodeText) GetPackageLen(buf []byte) int
type OnSocket ¶
type OnSocket interface { /** 连接上服务器回调,或者服务器accept某个客户端连接 */ OnConnect(conn Conn) /** 只要我们曾经连接上服务器过,OnClose必定会回调。代表一个当前的socket已经关闭 @param conn 连接 @param byLocalNotRemote 是否是本地主动本地断开;true:对服务器而言就是服务器把客户端断开,对客户端而言就是客户端主动断服务器 */ OnClose(conn Conn, byLocalNotRemote bool) /** 连接超时,写入超时,读取超时回调 */ OnTimeout(conn Conn) /** 网络错误回调,之后直接close */ OnNetErr(conn Conn) /** 接受到信息 @return 返回true表示可以继续热恋,false表示要分手了。 */ OnRecvMsg(conn Conn, buf []byte) bool }
* Socket 事件分发
type OnSocketServer ¶
type OnSocketServer interface { OnSocket OnServerListen() OnServerErr(StackError) //这里OnServerClose始终会回调 OnServerClose() }
type ServerSocket ¶
type ServerSocket struct { StatusConnServer // contains filtered or unexported fields }
func NewServer ¶
func NewServer(address string, ttl time.Duration, rTtl time.Duration, onSocket OnSocketServer, clientDDB DataDecodeBase) *ServerSocket
@ttl 客户端发送超时 @rTtl 客户端读取超时 0表示永远等待读取。
func NewServerIp ¶
func NewServerIp(ip string, port uint16, onSocket OnSocketServer, clientDDB DataDecodeBase) *ServerSocket
func (*ServerSocket) Listen ¶
func (s *ServerSocket) Listen() error
func (*ServerSocket) OnClose ¶
func (s *ServerSocket) OnClose(conn Conn, byLocalNotRemote bool)
只要我们曾经连接上服务器过,OnClose必定会回调。代表一个当前的socket已经关闭
func (*ServerSocket) OnRecvMsg ¶
func (s *ServerSocket) OnRecvMsg(conn Conn, buf []byte) bool
接受到信息 @return 返回true表示可以继续热恋,false表示要分手了。
func (*ServerSocket) OnTimeout ¶
func (s *ServerSocket) OnTimeout(conn Conn)
连接超时,写入超时,读取超时回调,之后会调用OnClose
func (*ServerSocket) Shutdown ¶
func (s *ServerSocket) Shutdown()
type StackError ¶
type Status ¶
type Status struct {
// contains filtered or unexported fields
}
func (*Status) ChangeStatusAll ¶
type StatusConnServer ¶
type StatusConnServer struct { Status // contains filtered or unexported fields }
Click to show internal directories.
Click to hide internal directories.