Documentation ¶
Overview ¶
Package connect https://github.com/xtaci/kcp-go
Package connect https://github.com/gorilla/websocket
Index ¶
- Constants
- func Encode(mp *MyProtocol) []byte
- type KcpSocket
- type MyProtocol
- type MySocket
- func (socket *MySocket) AsyncResult(socketId uint32, f func(bytes []byte))
- func (socket *MySocket) InvokeMethod(socketId uint32, message []byte)
- func (socket *MySocket) OnClose(close func(socketId uint32))
- func (socket *MySocket) SendMessage(bytes []byte)
- func (socket *MySocket) SendSelectMessage(bytes []byte, socketIds ...uint32)
- type Socket
- type SocketClose
- type TcpSocket
- type Tls
- type WebSocket
Constants ¶
View Source
const Addr = "0.0.0.0:12345"
Addr ----------------- 这里时测试数据
View Source
const HelloMsg = "HelloWorld"
Variables ¶
This section is empty.
Functions ¶
Types ¶
type MyProtocol ¶
MyProtocol 定义一个自定义协议的结构体,包含消息的长度、类型和内容
func (*MyProtocol) SetData ¶
func (p *MyProtocol) SetData(data []byte) *MyProtocol
type MySocket ¶
type MySocket struct { UuidOnCoon sync.Map // 连接 //queue chan []byte //结果 Pool *common.Pool //线程池 Tls *Tls Debug bool // 是否开启调试模式,开启后会打印发送日志 // contains filtered or unexported fields }
MySocket Socket接口的通用字段
func (*MySocket) AsyncResult ¶
AsyncResult 这里是同步的,因为流不允许并发写入
func (*MySocket) InvokeMethod ¶
InvokeMethod 此处添加至线程池进行远程调用
func (*MySocket) SendSelectMessage ¶
SendSelectMessage 选择id发送
type Socket ¶
type Socket interface { // ListenBack 监听连接收到的消息,回写到上层方法,当返回 byte 不为空时则写入到客户端, // uuid 为连接建立时的唯一id,message为具体消息内容 ListenBack(func(uuid uint32, message []byte) []byte) ListenAddr(addr string) SendSelectMessage(bytes []byte, socketIds ...uint32) SendMessage(bytes []byte) OnClose(close func(socketId uint32)) }
type SocketClose ¶ added in v0.0.28
type SocketClose interface {
OnClose(socketId uint32)
}
Click to show internal directories.
Click to hide internal directories.