WebSocket runtime

Technical reference of Runtime WebSocket.

This API is used in WebSocket.


Symbols

SymbolClassDescription
BindSocketIdentityfuncInstall BindSocketIdentity.
BindSocketChannelTransportfuncInstall BindSocketChannelTransport.
EmitSocketChannelEventfuncEmite EmitSocketChannelEvent.
LeaveSocketChannelfuncWithdraw LeaveSocketChannel.
SocketGroupBindingstypeSocketGroupBindings defines a public type of API.
BindSocketGroupsfuncInstall BindSocketGroups.
BindSocketLocationfuncInstall BindSocketLocation.
BindSocketSiblingsfuncInstall BindSocketSiblings.
BindSocketSiblingsEmitfuncInstall BindSocketSiblingsEmit.
BindSocketSiblingsDisconnectfuncInstall BindSocketSiblingsDisconnect.
BindSocketPacketfuncInstall BindSocketPacket.
WriteSocketPacketfuncWrite WriteSocketPacket.
BindSocketDisconnectfuncInstall BindSocketDisconnect.
BindSocketEmitfuncInstall BindSocketEmit.
BindSocketRequestfuncInstall BindSocketRequest.
BindSocketClusterRequestfuncInstall BindSocketClusterRequest.
RouteSocketClusterRequestfuncSend a socket request to another instance.
BindSocketClusterCancelfuncInstall BindSocketClusterCancel.
CancelSocketClusterRequestfuncCancel a distributed request pending.
SocketRegistryBindingstypeSocketRegistryBindings defines a public type of API.
BindSocketRegistryfuncInstall BindSocketRegistry.
GroupRegistryBindingstypeGroupRegistryBindings defines a public type of API.
BindGroupsfuncInstall BindGroups.
NewChannelGenerationCandidatefuncBuild NewChannelGenerationCandidate.
ValidateChannelGenerationCandidatefuncValida ValidateChannelGenerationCandidate.
CommitChannelGenerationfuncIt activates a validated channel generation.
AbortChannelGenerationfuncDiscard a candidate generation.
ChannelRuntimeBindingstypeChannelRuntimeBindings defines a public type of API.
BindChannelRuntimefuncInstall BindChannelRuntime.
ChannelRegistryBindingstypeChannelRegistryBindings defines a public type of API.
BindChannelRegistryfuncInstall BindChannelRegistry.

BindSocketIdentity

Declaration:

gox
func BindSocketIdentity(s *Socket) func(string)

Install BindSocketIdentity.

Parameters

ParameterTypeDescription
s*SocketType value *Socket required by the operation.

Returns

ReturnTypeDescription
valuefunc(string)Type value func(string) produced by the operation.

BindSocketChannelTransport

Declaration:

gox
func BindSocketChannelTransport(socket *Socket, transport SocketChannelTransport)

Install BindSocketChannelTransport.

Parameters

ParameterTypeDescription
socket*SocketType value *Socket required by the operation.
transportSocketChannelTransportType value SocketChannelTransport required by the operation.

EmitSocketChannelEvent

Declaration:

gox
func EmitSocketChannelEvent(socket *Socket, channelID, event string, values []any) error

Emite EmitSocketChannelEvent.

Parameters

ParameterTypeDescription
socket*SocketType value *Socket required by the operation.
``channelIDType value channelID required by the operation.
eventstringName of the event.
values[]anyValues provided to the operation.

Returns

ReturnTypeDescription
errerrornil if the operation ends correctly; otherwise, the error produced.

Behavior

The operation returns an error when it cannot complete the above contract.

Errors

EmitSocketChannelEvent returns an error when the arguments, the status of the receiver or the underlying operation make it impossible to complete the call.

Usage syntax

gox
err := gox.EmitSocketChannelEvent(nil, value, "event", value)

LeaveSocketChannel

Declaration:

gox
func LeaveSocketChannel(socket *Socket, channelID string, reason ChannelDisconnectReason) error

Withdraw LeaveSocketChannel.

Parameters

ParameterTypeDescription
socket*SocketType value *Socket required by the operation.
channelIDstringType value string required by the operation.
reasonChannelDisconnectReasonType value ChannelDisconnectReason required by the operation.

Returns

ReturnTypeDescription
errerrornil if the operation ends correctly; otherwise, the error produced.

Behavior

The operation returns an error when it cannot complete the above contract.

Errors

LeaveSocketChannel returns an error when the arguments, the status of the receiver or the underlying operation make it impossible to complete the call.

Usage syntax

gox
err := gox.LeaveSocketChannel(nil, value, value)

SocketGroupBindings

Declaration:

gox
type SocketGroupBindings struct {
	Join     func(group string) error
	Leave    func(group string) error
	LeaveAll func() error
	Groups   func() []string
	EmitTo   func(group string, event string, values []any)
}

SocketGroupBindings defines a public type of API.

Fields

FieldTypeDescription
Joinfunc(group string) errorPublic data associated with Join.
Leavefunc(group string) errorPublic data associated with Leave.
LeaveAllfunc() errorPublic data associated with LeaveAll.
Groupsfunc() []stringPublic data associated with Groups.
EmitTofunc(group string, event string, values []any)Public data associated with EmitTo.

BindSocketGroups

Declaration:

gox
func BindSocketGroups(s *Socket, bindings SocketGroupBindings)

Install BindSocketGroups.

Parameters

ParameterTypeDescription
s*SocketType value *Socket required by the operation.
bindingsSocketGroupBindingsType value SocketGroupBindings required by the operation.

BindSocketLocation

Declaration:

gox
func BindSocketLocation(s *Socket, instanceID string, local bool)

Install BindSocketLocation.

Parameters

ParameterTypeDescription
s*SocketType value *Socket required by the operation.
instanceIDstringType value string required by the operation.
localboolType value bool required by the operation.

BindSocketSiblings

Declaration:

gox
func BindSocketSiblings(socket *Socket, resolve func() []*Socket)

Install BindSocketSiblings.

Parameters

ParameterTypeDescription
socket*SocketType value *Socket required by the operation.
resolve func()[]*SocketType value []*Socket required by the operation.

BindSocketSiblingsEmit

Declaration:

gox
func BindSocketSiblingsEmit(socket *Socket, resolve func() []*Socket, emit func(event string, values []any))

Install BindSocketSiblingsEmit.

Parameters

ParameterTypeDescription
socket*SocketType value *Socket required by the operation.
resolve func()[]*SocketType value []*Socket required by the operation.
emit func(event string[]any)Type value []any) required by the operation.
values[]any)Values provided to the operation.

BindSocketSiblingsDisconnect

Declaration:

gox
func BindSocketSiblingsDisconnect(socket *Socket, disconnect func(code WSCloseCode))

Install BindSocketSiblingsDisconnect.

Parameters

ParameterTypeDescription
socket*SocketType value *Socket required by the operation.
disconnect func(codeWSCloseCode)Type value WSCloseCode) required by the operation.

BindSocketPacket

Declaration:

gox
func BindSocketPacket(s *Socket, write func(event string, packet []byte) error)

Install BindSocketPacket.

Parameters

ParameterTypeDescription
s*SocketType value *Socket required by the operation.
write func(event stringerrorType value error required by the operation.
packet []byte)errorType value error required by the operation.

WriteSocketPacket

Declaration:

gox
func WriteSocketPacket(s *Socket, event string, packet []byte) error

Write WriteSocketPacket.

Parameters

ParameterTypeDescription
s*SocketType value *Socket required by the operation.
eventstringName of the event.
packet[]byteType value []byte required by the operation.

Returns

ReturnTypeDescription
errerrornil if the operation ends correctly; otherwise, the error produced.

Behavior

The operation returns an error when it cannot complete the above contract.

Errors

WriteSocketPacket returns an error when the arguments, the status of the receiver or the underlying operation make it impossible to complete the call.


BindSocketDisconnect

Declaration:

gox
func BindSocketDisconnect(s *Socket, disconnect func(code WSCloseCode, reason string))

Install BindSocketDisconnect.

Parameters

ParameterTypeDescription
s*SocketType value *Socket required by the operation.
disconnect func(code WSCloseCodestring)Type value string) required by the operation.
reasonstring)Type value string) required by the operation.

BindSocketEmit

Declaration:

gox
func BindSocketEmit(s *Socket, emit func(event string, values []any) error)

Install BindSocketEmit.

Parameters

ParameterTypeDescription
s*SocketType value *Socket required by the operation.
emit func(event stringerrorType value error required by the operation.
values []any)errorType value error required by the operation.

BindSocketRequest

Declaration:

gox
func BindSocketRequest(s *Socket, request func(event string, values []any, out any) error)

Install BindSocketRequest.

Parameters

ParameterTypeDescription
s*SocketType value *Socket required by the operation.
request func(event stringerrorType value error required by the operation.
values []anyerrorType value error required by the operation.
out any)errorType value error required by the operation.

BindSocketClusterRequest

Declaration:

gox
func BindSocketClusterRequest(s *Socket, request func(originInstanceID string, correlationID []byte, packet []byte) error)

Install BindSocketClusterRequest.

Parameters

ParameterTypeDescription
s*SocketType value *Socket required by the operation.
request func(originInstanceID stringerrorType value error required by the operation.
correlationID []byteerrorType value error required by the operation.
packet []byte)errorType value error required by the operation.

RouteSocketClusterRequest

Declaration:

gox
func RouteSocketClusterRequest(s *Socket, originInstanceID string, correlationID []byte, packet []byte) error

Send a socket request to another instance.

Parameters

ParameterTypeDescription
s*SocketType value *Socket required by the operation.
originInstanceIDstringType value string required by the operation.
correlationID[]byteType value []byte required by the operation.
packet[]byteType value []byte required by the operation.

Returns

ReturnTypeDescription
errerrornil if the operation ends correctly; otherwise, the error produced.

Behavior

The operation returns an error when it cannot complete the above contract.

Errors

RouteSocketClusterRequest returns an error when the arguments, the status of the receiver or the underlying operation make it impossible to complete the call.


BindSocketClusterCancel

Declaration:

gox
func BindSocketClusterCancel(s *Socket, cancel func(correlationID []byte) bool)

Install BindSocketClusterCancel.

Parameters

ParameterTypeDescription
s*SocketType value *Socket required by the operation.
cancel func(correlationID []byte)boolType value bool required by the operation.

CancelSocketClusterRequest

Declaration:

gox
func CancelSocketClusterRequest(s *Socket, correlationID []byte) bool

Cancel a distributed request pending.

Parameters

ParameterTypeDescription
s*SocketType value *Socket required by the operation.
correlationID[]byteType value []byte required by the operation.

Returns

ReturnTypeDescription
valueboolIt indicates the result of the check.

SocketRegistryBindings

Declaration:

gox
type SocketRegistryBindings struct {
	All               func() []*Socket
	Count             func() int
	FindByID          func(id string) (*Socket, bool)
	FindBySessionID   func(sessionID string) []*Socket
	Emit              func(event string, values []any)
	EmitSession       func(sessionID string, event string, values []any)
	Disconnect        func(code WSCloseCode)
	DisconnectSession func(sessionID string, code WSCloseCode)
}

SocketRegistryBindings defines a public type of API.

Fields

FieldTypeDescription
Allfunc() []*SocketPublic data associated with All.
Countfunc() intQuantity recorded.
FindByIDfunc(id string) (*Socket, bool)Associated identifier.
FindBySessionIDfunc(sessionID string) []*SocketAssociated identifier.
Emitfunc(event string, values []any)Public data associated with Emit.
EmitSessionfunc(sessionID string, event string, values []any)Public data associated with EmitSession.
Disconnectfunc(code WSCloseCode)Public data associated with Disconnect.
DisconnectSessionfunc(sessionID string, code WSCloseCode)Public data associated with DisconnectSession.

BindSocketRegistry

Declaration:

gox
func BindSocketRegistry(bindings SocketRegistryBindings) func()

Install BindSocketRegistry.

Parameters

ParameterTypeDescription
bindingsSocketRegistryBindingsType value SocketRegistryBindings required by the operation.

Returns

ReturnTypeDescription
valuefunc()Type value func() produced by the operation.

GroupRegistryBindings

Declaration:

gox
type GroupRegistryBindings struct {
	List         func() []string
	Members      func(group string) []*Socket
	Count        func() int
	CountMembers func(group string) int
	EmitTo       func(group string, event string, values []any)
}

GroupRegistryBindings defines a public type of API.

Fields

FieldTypeDescription
Listfunc() []stringPublic data associated with List.
Membersfunc(group string) []*SocketPublic data associated with Members.
Countfunc() intQuantity recorded.
CountMembersfunc(group string) intQuantity recorded.
EmitTofunc(group string, event string, values []any)Public data associated with EmitTo.

BindGroups

Declaration:

gox
func BindGroups(bindings GroupRegistryBindings) func()

Install BindGroups.

Parameters

ParameterTypeDescription
bindingsGroupRegistryBindingsType value GroupRegistryBindings required by the operation.

Returns

ReturnTypeDescription
valuefunc()Type value func() produced by the operation.

NewChannelGenerationCandidate

Declaration:

gox
func NewChannelGenerationCandidate(channel *Channel, version string) *Channel

Build NewChannelGenerationCandidate.

Parameters

ParameterTypeDescription
channel*ChannelType value *Channel required by the operation.
versionstringType value string required by the operation.

Returns

ReturnTypeDescription
value*ChannelType value *Channel produced by the operation.

Usage syntax

gox
value := gox.NewChannelGenerationCandidate(nil, value)

ValidateChannelGenerationCandidate

Declaration:

gox
func ValidateChannelGenerationCandidate(channel, candidate *Channel) error

Valida ValidateChannelGenerationCandidate.

Parameters

ParameterTypeDescription
``channelType value channel required by the operation.
candidate*ChannelType value *Channel required by the operation.

Returns

ReturnTypeDescription
errerrornil if the operation ends correctly; otherwise, the error produced.

Behavior

The operation returns an error when it cannot complete the above contract.

Errors

ValidateChannelGenerationCandidate returns an error when the arguments, the status of the receiver or the underlying operation make it impossible to complete the call.

Usage syntax

gox
err := gox.ValidateChannelGenerationCandidate(value, nil)

CommitChannelGeneration

Declaration:

gox
func CommitChannelGeneration(channel, candidate *Channel) error

It activates a validated channel generation.

Parameters

ParameterTypeDescription
``channelType value channel required by the operation.
candidate*ChannelType value *Channel required by the operation.

Returns

ReturnTypeDescription
errerrornil if the operation ends correctly; otherwise, the error produced.

Behavior

The operation returns an error when it cannot complete the above contract.

Errors

CommitChannelGeneration returns an error when the arguments, the status of the receiver or the underlying operation make it impossible to complete the call.

Usage syntax

gox
err := gox.CommitChannelGeneration(value, nil)

AbortChannelGeneration

Declaration:

gox
func AbortChannelGeneration(candidate *Channel)

Discard a candidate generation.

Parameters

ParameterTypeDescription
candidate*ChannelType value *Channel required by the operation.

Usage syntax

gox
gox.AbortChannelGeneration(nil)

ChannelRuntimeBindings

Declaration:

gox
type ChannelRuntimeBindings struct {
	Members  func() []*Socket
	Emit     func(event string, values []any) error
	Leave    func(socket *Socket) error
	Close    func() error
	IsClosed func() bool
}

ChannelRuntimeBindings defines a public type of API.

Fields

FieldTypeDescription
Membersfunc() []*SocketPublic data associated with Members.
Emitfunc(event string, values []any) errorPublic data associated with Emit.
Leavefunc(socket *Socket) errorPublic data associated with Leave.
Closefunc() errorPublic data associated with Close.
IsClosedfunc() boolPublic data associated with IsClosed.

BindChannelRuntime

Declaration:

gox
func BindChannelRuntime(channel *Channel, bindings ChannelRuntimeBindings)

Install BindChannelRuntime.

Parameters

ParameterTypeDescription
channel*ChannelType value *Channel required by the operation.
bindingsChannelRuntimeBindingsType value ChannelRuntimeBindings required by the operation.

ChannelRegistryBindings

Declaration:

gox
type ChannelRegistryBindings struct {
	Get   func(id string) (*Channel, bool)
	List  func() []*Channel
	Count func() int
}

ChannelRegistryBindings defines a public type of API.

Fields

FieldTypeDescription
Getfunc(id string) (*Channel, bool)Query callback.
Listfunc() []*ChannelPublic data associated with List.
Countfunc() intQuantity recorded.

BindChannelRegistry

Declaration:

gox
func BindChannelRegistry(bindings ChannelRegistryBindings) func()

Install BindChannelRegistry.

Parameters

ParameterTypeDescription
bindingsChannelRegistryBindingsType value ChannelRegistryBindings required by the operation.

Returns

ReturnTypeDescription
valuefunc()Type value func() produced by the operation.

See also

Next step

Continue with Benchmarks instrumentation.

Runtime benchmarks