Getting Started¶
Connecting¶
First step to connect to a Socket.IO server is to include its namespace (Best.SocketIO) and create a SocketManager instance:
The official Socket.IO server implementation binds to the /socket.io/ path, and the client will append it to the uri if the uri's path part isn't present. If you used a different path, you can include it in the uri declaration.
By default, SocketManager
going to start connecting to the server as soon as a namespace is accessed through the Socket
property or GetSocket
function:
This auto connection can be disabled by using and setting up a SocketOptions
instance:
This way the SocketManager
will start connecting to the server only when its Open
function is called. Check out the SocketOptions topic for more options and callbacks!
Open
and any other functions of the SocketManager
and Socket
are non-blocking, they will return almost immediately aren't waiting for a server response.
The Connect Event¶
To get notified when the connection to the server completes, we can subscribe to the connect
default event:
Disconnecting¶
SocketManager
's Close
function closes all sockets, shuts down the transport and no more communication is done to the server. Calling Disconnect
on a socket disconnects only that socket, communication through other sockets are still possible. Disconnecting the last socket will also close the SocketManager.
Complete Example¶
To put it together, here's a complete example.
Example
Getting-started isn't over yet, read the how to subscribe to and send events topics too!