Class SocketIOClient
- Namespace
- Firesplash.GameDevAssets.SocketIOPlus
- Assembly
- Firesplash.GameDevAssets.SocketIOPlus.dll
This MonoBehavior derives from EngineIOClient and implements the main Socket.IO Manager logic on top of Engine.IO. It implements Socket.IO protocol version 5 (which is used by Socket.IO v3 and v4)
[DisallowMultipleComponent]
[AddComponentMenu("Networking/Socket.IO/Socket.IO Client")]
public class SocketIOClient : EngineIOClient
- Inheritance
-
SocketIOClient
- Inherited Members
Fields
maxConnectAttempts
If the connection (or a reconnect) is not successful after n attempts, cancel trying to (re)connect. A value of zero means infinitely.
public int maxConnectAttempts
Field Value
raisingReconnectDelay
After a failure, (re)connection attempts will be delayed by initially one second. On every failure the delay is raised by 50% and ceiled (1, 2, 3, 5, 8, 12, ...) up to 60 seconds. On a successful (re)connect this delay is reset to one second. If you set this value to false, the delay will always be one second +/-20% jitter.
public bool raisingReconnectDelay
Field Value
Properties
D
This is a shorthand to access the default namespace without having to write the whole namespace call every time for simple applications.
public SocketIONamespace D { get; }
Property Value
DefaultNamespace
This is a shorthand to access the default namespace without having to write the whole namespace call every time for simple applications. Want it even shorter? Use "D" :o)
public SocketIONamespace DefaultNamespace { get; }
Property Value
Methods
Connect(string)
Connect the client to the server
public override void Connect(string pServerAddress = null)
Parameters
pServerAddress
string
Disconnect()
Disconnect the Engine.IO client
public override void Disconnect()
GetNamespace(string, bool)
Returns the API of the Socket.IO Client for the given namesapce and connects to the namespace if it is not already connected. If the underlaying transport is not completely connected yet, the connect to the namespace is delayed until the transport is ready. Namespaces will always reconnect when the manager reconnects, unless you directly call "Disconnect()" on the namespace itself. A Namespace that has been disconnected directly, can be reconnected by calling "Connect()" on the namespace.
public SocketIONamespace GetNamespace(string namespacePath, bool connectIfNotExists = true)
Parameters
namespacePath
stringconnectIfNotExists
boolConnect to this namespace if it is not connected (returns null if false and not existing)
Returns
GetParser()
protected virtual Parser GetParser()
Returns
LateUpdate()
protected void LateUpdate()
Off(string, UnityAction<object>)
Unregisters a previously registered manager event callback
public void Off(string eventName, UnityAction<object> callback)
Parameters
eventName
stringThe event name - For valid values see On(...)
callback
UnityAction<object>The callback to unregister
Exceptions
- DataTypes.SocketIOException
Thrown, if the given eventName is not a valid Manager event
On(string, UnityAction<object>)
Allows registering to "low level" manager events. This is NOT a namespaced event listener!
public void On(string eventName, UnityAction<object> callback)
Parameters
eventName
stringThe event name (one of error, reconnect, reconnect_attempt, reconnect_error, reconnect_failed)
callback
UnityAction<object>The callback to be called. The parameter contains values according to the official Socket.IO documentation. The Error event has a string. For events having no payload, the value is null.
Exceptions
- DataTypes.SocketIOException
Thrown, if the given eventName is not a valid Manager event
SetAuthPayloadCallback(SocketIOAuthPayloadCallback)
This callback will be called whenever a namespace connects. If the callback returns a value other than null, it will be sent as authentication payload while connecting the namespace. The function is called from GetNamespace, so if you call this method from a thread, the callback also runs on a thread. Internally generated connect sequences always call the callback from the main thread.
public void SetAuthPayloadCallback(DataTypes.SocketIOAuthPayloadCallback callback)
Parameters
callback
DataTypes.SocketIOAuthPayloadCallbackA SocketIOAuthPayloadCallback delegate
SetParser(Parser)
You can override the used parser using this method. You can implement your own (or a publicly available) parser and message format. Please remember, that server and clients need to use the same parser (or better said the same message format).
public void SetParser(Parser newParser)
Parameters
newParser
Parser