Documentation ¶
Index ¶
- Constants
- Variables
- func PutPMessage(msg *P_MESSAGE)
- func PutPMessageIntfs(message interface{})
- func RegisterHandler(cmd int32, h Handler)
- type ConnOption
- type ConnType
- type Connection
- func Accept(ctx context.Context, w http.ResponseWriter, r *http.Request, ...) (*Connection, error)
- func AcceptGin(ctx *gin.Context, meta ConnectionMeta, opts ...ConnOption) (*Connection, error)
- func Connect(ctx context.Context, sId, sUrl string, secureWss bool, header http.Header, ...) (*Connection, error)
- func (c *Connection) Charset() int
- func (c *Connection) GetCommDataValue(key string) (interface{}, bool)
- func (c *Connection) GetPullChannel(notifyType int) (chan struct{}, bool)
- func (c *Connection) Id() string
- func (c *Connection) IncrCommDataValueBy(key string, delta int)
- func (c *Connection) IsDisplaced() bool
- func (c *Connection) IsStopped() bool
- func (c *Connection) KickClient(displace bool)
- func (c *Connection) KickServer(displace bool)
- func (c *Connection) RefreshDeadline()
- func (c *Connection) RemoveCommDataValue(key string)
- func (c *Connection) SendMsg(ctx context.Context, payload *P_MESSAGE, sc SendCallback) (err error)
- func (c *Connection) SendPullNotify(ctx context.Context, pullChannel int) (err error)
- func (c *Connection) SetCommDataValue(key string, value interface{})
- func (c *Connection) Type() int
- func (c *Connection) UserId() string
- func (c *Connection) Version() int
- type ConnectionMeta
- type Handler
- type Hub
- type IConnCallback
- type IHeartbeatCallback
- type P_MESSAGE
- type P_S2C
- type SendCallback
Constants ¶
View Source
const ( CONN_TYPE_CLIENT = 0 CONN_TYPE_SERVER = 1 )
View Source
const ( CHARSET_UTF8 = 0 CHARSET_GBK = 1 )
Variables ¶
View Source
var ( ReadWait = conf.ExtDuration("ws.readWait", 60*time.Second) //读等待 WriteWait = conf.ExtDuration("ws.writeWait", 60*time.Second) //写等待 PingPeriod = WriteWait * 4 / 10 //ping间隔应该小于写等待时间 NetTemporaryWait = 500 * time.Millisecond //网络抖动重试等待 )
配置项
View Source
var ( P_S2C_name = map[int32]string{ 0: "s2c_connected", 1: "s2c_err_displace", } P_S2C_value = map[string]int32{ "s2c_connected": 0, "s2c_err_displace": 1, } )
Enum value maps for P_S2C.
View Source
var Clients = newHub()
View Source
var File_ws_msg_proto protoreflect.FileDescriptor
View Source
var (
Handlers = make(map[int32]Handler)
)
View Source
var Servers = newHub()
Functions ¶
func PutPMessage ¶
func PutPMessage(msg *P_MESSAGE)
func PutPMessageIntfs ¶
func PutPMessageIntfs(message interface{})
Types ¶
type ConnOption ¶
type ConnOption func(*Connection)
连接动态参数选项
func HeartbeatCbOption ¶
func HeartbeatCbOption(heartbeatCallback IHeartbeatCallback) ConnOption
func SendBufferOption ¶
func SendBufferOption(bufferSize int) ConnOption
func SrvPullChannelsOption ¶
func SrvPullChannelsOption(channels []int) ConnOption
为每种消息拉取逻辑分别注册不同的通道
func SrvUpgraderOption ¶
func SrvUpgraderOption(upgrader *websocket.Upgrader) ConnOption
服务端特有 upgrader定制
type Connection ¶
type Connection struct {
// contains filtered or unexported fields
}
websocket连接封装
func Accept ¶
func Accept(ctx context.Context, w http.ResponseWriter, r *http.Request, meta ConnectionMeta, opts ...ConnOption) (*Connection, error)
func AcceptGin ¶
func AcceptGin(ctx *gin.Context, meta ConnectionMeta, opts ...ConnOption) (*Connection, error)
func Connect ¶
func Connect(ctx context.Context, sId, sUrl string, secureWss bool, header http.Header, opts ...ConnOption) (*Connection, error)
func (*Connection) Charset ¶
func (c *Connection) Charset() int
func (*Connection) GetCommDataValue ¶
func (c *Connection) GetCommDataValue(key string) (interface{}, bool)
连接数据存储结构
func (*Connection) GetPullChannel ¶
func (c *Connection) GetPullChannel(notifyType int) (chan struct{}, bool)
func (*Connection) Id ¶
func (c *Connection) Id() string
func (*Connection) IncrCommDataValueBy ¶
func (c *Connection) IncrCommDataValueBy(key string, delta int)
func (*Connection) IsDisplaced ¶
func (c *Connection) IsDisplaced() bool
func (*Connection) IsStopped ¶
func (c *Connection) IsStopped() bool
func (*Connection) KickClient ¶
func (c *Connection) KickClient(displace bool)
displace=true,通常在集群环境下,踢掉在其他集群节点建立的连接,当前节点不需要主动调用
func (*Connection) KickServer ¶
func (c *Connection) KickServer(displace bool)
displace=true,通常在集群环境下,踢掉在其他集群节点建立的连接,当前节点不需要主动调用
func (*Connection) RefreshDeadline ¶
func (c *Connection) RefreshDeadline()
func (*Connection) RemoveCommDataValue ¶
func (c *Connection) RemoveCommDataValue(key string)
func (*Connection) SendMsg ¶
func (c *Connection) SendMsg(ctx context.Context, payload *P_MESSAGE, sc SendCallback) (err error)
func (*Connection) SendPullNotify ¶
func (c *Connection) SendPullNotify(ctx context.Context, pullChannel int) (err error)
通知指定消息通道转发消息
func (*Connection) SetCommDataValue ¶
func (c *Connection) SetCommDataValue(key string, value interface{})
func (*Connection) Type ¶
func (c *Connection) Type() int
func (*Connection) UserId ¶
func (c *Connection) UserId() string
func (*Connection) Version ¶
func (c *Connection) Version() int
type ConnectionMeta ¶
type ConnectionMeta struct { UserId string //userId Typed int //客户端类型枚举 DeviceId string //设备ID Version int //版本 Charset int //客户端使用的字符集 }
func (*ConnectionMeta) BuildConnId ¶
func (m *ConnectionMeta) BuildConnId() string
type Hub ¶
type Hub struct {
// contains filtered or unexported fields
}
连接管理器
func (*Hub) ConnectionIds ¶
func (*Hub) RangeConnsByFunc ¶
func (h *Hub) RangeConnsByFunc(f func(string, *Connection) bool)
type IConnCallback ¶
连接回调
type IHeartbeatCallback ¶
保活回调
type P_MESSAGE ¶
type P_MESSAGE struct { ProtocolId int32 `protobuf:"varint,1,opt,name=protocol_id,json=protocolId,proto3" json:"protocol_id,omitempty"` //消息协议ID Data []byte `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` //内容-自定义消息 // contains filtered or unexported fields }
func GetPMessage ¶
func GetPMessage() *P_MESSAGE
func (*P_MESSAGE) Descriptor
deprecated
func (*P_MESSAGE) GetProtocolId ¶
func (*P_MESSAGE) ProtoMessage ¶
func (*P_MESSAGE) ProtoMessage()
func (*P_MESSAGE) ProtoReflect ¶
func (x *P_MESSAGE) ProtoReflect() protoreflect.Message
type P_S2C ¶
type P_S2C int32
func (P_S2C) Descriptor ¶
func (P_S2C) Descriptor() protoreflect.EnumDescriptor
func (P_S2C) EnumDescriptor
deprecated
func (P_S2C) Number ¶
func (x P_S2C) Number() protoreflect.EnumNumber
func (P_S2C) Type ¶
func (P_S2C) Type() protoreflect.EnumType
Click to show internal directories.
Click to hide internal directories.