Documentation ¶
Index ¶
Constants ¶
View Source
const ( DefaultIP = "127.0.0.1" DefaultPort = 30117 UniqIDLength = 32 )
Variables ¶
Functions ¶
func DestroyGlobalSessionPool ¶
func DestroyGlobalSessionPool() error
Types ¶
type ClientSessionPool ¶
type ClientSessionPool struct {
// contains filtered or unexported fields
}
---------------------------------------------------- 用于客户端的session pool
func GetGlobalSessionPool ¶
func GetGlobalSessionPool(ip string, port int32, url string, size int32, callback WebSocketFunc) *ClientSessionPool
用于初始化并返回全局客户端的session pool
func (*ClientSessionPool) Destroy ¶
func (sp *ClientSessionPool) Destroy(err error) error
func (*ClientSessionPool) GetSession ¶
func (sp *ClientSessionPool) GetSession() (*Session, error)
获取可用session
type Message ¶
type Message struct { UniqID MessageID // 固定长度,用于识别命令 // op ws.OpCode // 先用固定的 Binary Data []byte WaitResponse bool // 发送成功后,是否还需要等待对方返回结果 RetChan chan *MessageResult }
约束条件: 返回结果的 UniqID 需要保持不变,方便收到结果后,找到对应的chan
type MessageResult ¶
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
func NewClientSession ¶
func NewClientSession(ip string, port int32, url string, callback WebSocketFunc) *Session
client端创建session,需要指定目标server的ip和端口
func NewServerSession ¶
func NewServerSession(w http.ResponseWriter, r *restful.Request, callback WebSocketFunc) *Session
server端创建session,需要指定http处理函数
func (*Session) Send ¶
func (s *Session) Send(data []byte, waitresponse bool) *MessageResult
session 内部将data封装为Message发送,并通过chan接收发送结果,Message的id需要内部生成 如果 waitresponse为true,则需要等待返回的结果
func (*Session) SendWithID ¶
func (s *Session) SendWithID(id MessageID, data []byte, waitresponse bool) *MessageResult
session 内部将data封装为Message发送,并通过chan接收发送结果,这儿指定了id,无需自动生成 如果 waitresponse为true,则需要等待返回的结果
Click to show internal directories.
Click to hide internal directories.