Documentation ¶
Index ¶
- Constants
- type BaseChannel
- type BaseClient
- type BaseMessage
- type BaseServer
- func (b *BaseServer) GetEncrypt() enctypthelper.IEncrypt
- func (b *BaseServer) GetSocketParse() ISocket
- func (b *BaseServer) NextId() uint64
- func (b *BaseServer) OnAccept(channelId uint64, addr string)
- func (b *BaseServer) OnClose(channelId uint64)
- func (b *BaseServer) OnRead(channelId uint64, message IMessage)
- func (b *BaseServer) SetOnAccept(onAccept func(uint64, string))
- func (b *BaseServer) SetOnClose(onClose func(uint64))
- func (b *BaseServer) SetOnRead(onRead func(uint64, IMessage))
- type BaseSocket
- type ConnProtocol
- type IChannel
- type IClient
- type IMessage
- type IServer
- type ISocket
- type MessageInfo
- type NetOperator
- type ParseData
- type TChannel
- type TClient
- type TServer
- type WChannel
- func (conn *WChannel) Close()
- func (conn *WChannel) CloseHandler(code int, text string) error
- func (conn *WChannel) GetAddr() string
- func (conn *WChannel) GetChannelId() uint64
- func (conn *WChannel) GetConn() *websocket.Conn
- func (conn *WChannel) SendMsg(message IMessage)
- func (conn *WChannel) Start()
- type WClient
- type WServer
- func (ser *WServer) AddChannel(channel *WChannel)
- func (ser *WServer) CheckOrigin(r *http.Request) bool
- func (ser *WServer) Close()
- func (ser *WServer) GetChannel(channelId uint64) IChannel
- func (ser *WServer) RemoveChannel(channelId uint64)
- func (ser *WServer) SendMessage(channelId uint64, message IMessage)
- func (ser *WServer) Server()
Constants ¶
View Source
const ( WebSocketTimeout = 5 * time.Second ReadBufferSize = 1024 WriteBufferSize = 1024 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BaseChannel ¶
type BaseChannel struct {
// contains filtered or unexported fields
}
type BaseClient ¶
type BaseClient struct {
// contains filtered or unexported fields
}
func NewBaseClient ¶
func NewBaseClient() *BaseClient
func (*BaseClient) SetEncrypt ¶
func (b *BaseClient) SetEncrypt(iEncrypt enctypthelper.IEncrypt)
func (*BaseClient) SetReadCall ¶
func (b *BaseClient) SetReadCall(readCall func(IMessage))
func (*BaseClient) SetSocket ¶
func (b *BaseClient) SetSocket(iSocket ISocket)
type BaseMessage ¶
func (*BaseMessage) GetHeader ¶
func (b *BaseMessage) GetHeader() []byte
func (BaseMessage) GetMessageData ¶
func (b BaseMessage) GetMessageData() []byte
func (BaseMessage) GetMsgId ¶
func (b BaseMessage) GetMsgId() int
func (*BaseMessage) Reset ¶
func (b *BaseMessage) Reset()
func (*BaseMessage) SetHeader ¶
func (b *BaseMessage) SetHeader(data []byte)
func (*BaseMessage) SetMessageData ¶
func (b *BaseMessage) SetMessageData(data []byte)
func (*BaseMessage) SetMsgId ¶
func (b *BaseMessage) SetMsgId(msgId int)
type BaseServer ¶
type BaseServer struct {
// contains filtered or unexported fields
}
func NewBaseServer ¶
func NewBaseServer(addr string) *BaseServer
func (*BaseServer) GetEncrypt ¶
func (b *BaseServer) GetEncrypt() enctypthelper.IEncrypt
func (*BaseServer) GetSocketParse ¶
func (b *BaseServer) GetSocketParse() ISocket
func (*BaseServer) NextId ¶
func (b *BaseServer) NextId() uint64
func (*BaseServer) OnAccept ¶
func (b *BaseServer) OnAccept(channelId uint64, addr string)
func (*BaseServer) OnClose ¶
func (b *BaseServer) OnClose(channelId uint64)
func (*BaseServer) OnRead ¶
func (b *BaseServer) OnRead(channelId uint64, message IMessage)
func (*BaseServer) SetOnAccept ¶
func (b *BaseServer) SetOnAccept(onAccept func(uint64, string))
func (*BaseServer) SetOnClose ¶
func (b *BaseServer) SetOnClose(onClose func(uint64))
func (*BaseServer) SetOnRead ¶
func (b *BaseServer) SetOnRead(onRead func(uint64, IMessage))
type BaseSocket ¶
type BaseSocket struct { }
BaseSocket tcp原始解析,需要跟客户端保持一致 1、获取4字节长度 2、根据长度获取全部数据 发送时相同:1、前4字节为长度,后面为打包后的数据
func (*BaseSocket) ParseSocket ¶
func (base *BaseSocket) ParseSocket(connection io.Reader, parseData *ParseData)
func (*BaseSocket) UnParseSocket ¶
func (base *BaseSocket) UnParseSocket(message IMessage) (data []byte, err error)
type IClient ¶
type IClient interface { Connect(addr string) error Close() error SendMsg(message IMessage) Read() SetReadCall(readCall func(IMessage)) SetEncrypt(iEncrypt enctypthelper.IEncrypt) SetSocket(iSocket ISocket) }
func NewTClient ¶
func NewWClient ¶
type IMessage ¶
type IMessage interface { GetMsgId() int SetMsgId(int) GetMessageData() []byte SetMessageData([]byte) SetHeader(data []byte) GetHeader() []byte Reset() }
func NewMessage ¶
func NewMessage() IMessage
type IServer ¶
type IServer interface { Server() // 服务启动 Close() // 关闭连接 SendMessage(channelId uint64, message IMessage) RemoveChannel(uint64) SetOnAccept(onAccept func(uint64, string)) SetOnRead(onRead func(uint64, IMessage)) SetOnClose(onClose func(uint64)) GetSocketParse() ISocket GetEncrypt() enctypthelper.IEncrypt OnRead(channelId uint64, message IMessage) }
type MessageInfo ¶
type MessageInfo struct {
// contains filtered or unexported fields
}
type NetOperator ¶
type ParseData ¶
type ParseData struct { Error error // contains filtered or unexported fields }
func NewParseData ¶
func NewParseData() *ParseData
func (*ParseData) ResetTmpData ¶
type TChannel ¶
type TChannel struct { *BaseChannel // contains filtered or unexported fields }
func NewChannel ¶
NewChannel 创建连接
func (*TChannel) GetChannelId ¶
func (*TChannel) GetConnKey ¶
type TClient ¶
type TClient struct { *BaseClient // contains filtered or unexported fields }
type TServer ¶
type TServer struct {
*BaseServer
}
func NewTServer ¶
func (*TServer) AddChannel ¶
func (*TServer) GetChannel ¶
func (*TServer) RemoveChannel ¶
func (*TServer) SendMessage ¶
type WChannel ¶
type WChannel struct { *BaseChannel // contains filtered or unexported fields }
func NewWChannel ¶
NewWChannel 创建连接
func (*WChannel) GetChannelId ¶
type WClient ¶
type WClient struct { *BaseClient // contains filtered or unexported fields }
type WServer ¶
type WServer struct { *BaseServer // contains filtered or unexported fields }
func NewWServer ¶
func (*WServer) AddChannel ¶
func (*WServer) GetChannel ¶
func (*WServer) RemoveChannel ¶
func (*WServer) SendMessage ¶
Click to show internal directories.
Click to hide internal directories.