Documentation
¶
Index ¶
Constants ¶
View Source
const ( NetEventTypeInvalid = 0 NetEventTypeUnreliableMessageReceived = 1 NetEventTypeReliableMessageReceived = 2 NetEventTypeServerInitialized = 3 NetEventTypeServerInitFailed = 4 NetEventTypeServerClosed = 5 NetEventTypeNewConnection = 6 NetEventTypeConnectionFailed = 7 NetEventTypeDisconnected = 8 NetEventTypeFatalError = 100 NetEventTypeWarning = 101 NetEventTypeLog = 102 )
View Source
const ( SignalingConnectionStateUninitialized = iota SignalingConnectionStateConnecting SignalingConnectionStateConnected SignalingConnectionStateDisconnection SignalingConnectionStateDisconnected )
Variables ¶
View Source
var INVALIDConnectionId = NewConnectionId(-1)
View Source
var NetEventDataTypeMap = map[string]int32{
"Null": 0,
"ByteArray": 1,
"UTF16String": 2,
}
View Source
var NetEventTypeITS = map[int]string{
0: "Invalid",
1: "UnreliableMessageReceived",
2: "ReliableMessageReceived",
3: "ServerInitialized",
4: "ServerInitFailed",
5: "ServerClosed",
6: "NewConnection",
7: "ConnectionFailed",
8: "Disconnected",
100: "FatalError",
101: "Warning",
102: "Log",
}
View Source
var NetEventTypeSTI = map[string]int{
"Invalid": 0,
"UnreliableMessageReceived": 1,
"ReliableMessageReceived": 2,
"ServerInitialized": 3,
"ServerInitFailed": 4,
"ServerClosed": 5,
"NewConnection": 6,
"ConnectionFailed": 7,
"Disconnected": 8,
"FatalError": 100,
"Warning": 101,
"Log": 102,
}
Functions ¶
This section is empty.
Types ¶
type ConnectionId ¶
type ConnectionId struct {
ID int16 `json:"id"`
}
func NewConnectionId ¶
func NewConnectionId(nid int16) *ConnectionId
type NetEventData ¶
type NetEventData struct { Type NetEventDataType StringData *string ObjectData []uint8 }
type NetEventDataType ¶
type NetEventDataType int
const ( NetEventDataTypeNull NetEventDataType = iota NetEventDataTypeByteArray NetEventDataTypeUTF16String )
func (NetEventDataType) String ¶
func (t NetEventDataType) String() string
type NetworkEvent ¶
type NetworkEvent struct { Type int `json:"type"` ConnectionId *ConnectionId `json:"connectionId"` Data *NetEventData `json:"data"` }
func FromByteArray ¶
func FromByteArray(arr []byte) (*NetworkEvent, error)
首先数据是小端字节序 example: arr := []byte{3, 2, 255, 255, 3, 0, 0, 0, 49, 0, 50, 0, 51, 0} arr[0]为事件类型(event_type, uint8), arr[1]为数据类型(data_type, uint8) arr[2:4]为connection_id( int16 ), arr[4:8]为数据长度(data_length, uint32), arr[8:data_length]为数据(data, uint16) arr 转换为 event_type = 3, data_type = 2, connection_id = -1, data_length = 3, data = "123"
func NewNetworkEvent ¶
func NewNetworkEvent(t int, conId *ConnectionId, data *NetEventData) *NetworkEvent
func ParseFromString ¶
func ParseFromString(str string) *NetworkEvent
func (*NetworkEvent) GetInfo ¶
func (ne *NetworkEvent) GetInfo() *NetEventData
func (*NetworkEvent) GetMessageData ¶
func (ne *NetworkEvent) GetMessageData() *NetEventData
func (*NetworkEvent) GetRawData ¶
func (ne *NetworkEvent) GetRawData() *NetEventData
func (*NetworkEvent) String ¶
func (ne *NetworkEvent) String() (output string)
func (*NetworkEvent) ToByteArray ¶
func (ne *NetworkEvent) ToByteArray() []byte
type PeerPool ¶
type PeerPool struct {
// contains filtered or unexported fields
}
func NewPeerPool ¶
type SignalingPeer ¶
type SignalingPeer struct {
// contains filtered or unexported fields
}
func NewSignalingPeer ¶
func NewSignalingPeer(pool *PeerPool, conn *websocket.Conn) *SignalingPeer
func (*SignalingPeer) Cleanup ¶
func (sp *SignalingPeer) Cleanup()
func (*SignalingPeer) GetName ¶
func (sp *SignalingPeer) GetName() string
type WebsocketNetworkServer ¶
type WebsocketNetworkServer struct {
// contains filtered or unexported fields
}
func NewWebsocketNetworkServer ¶
func NewWebsocketNetworkServer() *WebsocketNetworkServer
func (*WebsocketNetworkServer) OnConnection ¶
func (wns *WebsocketNetworkServer) OnConnection(socket *websocket.Conn, config *AppConfig)
Click to show internal directories.
Click to hide internal directories.