-
Notifications
You must be signed in to change notification settings - Fork 18
Connect to Server v7
- status: complete
- version: 7.x
A node
instance can connect to a nodeGame server through two types
of sockets:
- SocketIO: connects to the server through different network protocols using Socket.IO. It used, for example, for connections coming from a browser.
- SocketDirect: connects to the server via a shared object in the server. It is used for example by a logic, or a bot to connect to a game room.
Connect via SocketIO:
node.setup('socket', {
type: 'SocketIo',
// Other Socket.Io options, e.g:
reconnect: false
});
node.connect('/mychannel');
Connect via SocketDirect:
// A reference to the channel's socket must be obtained.
var channelSocketObject = channel.socket.
node.socket.setSocketType('SocketDirect', {
socket: channelSocketObject
});
node.connect();
The method node.connect
accepts an optional second parameter that
contains options to instruct the server how to handle the new
connection. For example, it is possible to specify the
client type and the starting room for the
connection.
// SocketIO options.
var ioOptions = {
query: 'clientType=player&startingRoom=myRoom'
};
node.connect('/mychannel', directOptions);
// SocketDirect options.
var directOptions = {
clientType: 'player',
startingRoom: 'myRoom'
};
node.connect(null, directOptions);
In production, it is recommended to disable connect parameters for
SocketIo connection. To do so, modify the sioQuery
option in the
channel configuration file.
Go back to the wiki Home.
Copyright (C) 2021 Stefano Balietti
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.