Connect
Start off a connection, based off connection type to brainCloud's Relay Servers. Connect options come in from "ROOM_ASSIGNED" lobby callback
Method Parameters
| Parameter | Description |
|---|---|
| connectionType | The connection type. INVALID, WEBSOCKET, TCP, UDP, MAX |
| options | Options sent in the connection |
Usage
http://localhost:3000
- C#
- C++
- Obj-C
- Java
- JavaScript
- Dart
- Roblox
- GDScript
- Lua
- Cloud Code
- Raw
RelayConnectionType connectionType = RelayConnectionType.WEBSOCKET;
Dictionary<string, object> options = null;
SuccessCallback successCallback = (response, cbObject) =>
{
Debug.Log(string.Format("Success | {0}", response));
};
FailureCallback failureCallback = (status, code, error, cbObject) =>
{
Debug.Log(string.Format("Failed | {0} {1} {2}", status, code, error));
};
_bc.RelayService.Connect(connectionType, options, successCallback, failureCallback);
_bc->getRelayService()->connect(eRelayConnectionType.WEBSOCKET, server.host, port, server.passcode, server.lobbyId, this);
_bc->getRelayService()->connect(eRelayConnectionType.WEBSOCKET, server.host, port, server.passcode, server.lobbyId, this);
_bc->getRelayService()->connect(eRelayConnectionType.WEBSOCKET, server.host, port, server.passcode, server.lobbyId, this);
_bc.relay.connect(eRelayConnectionType.WEBSOCKET, server.host, port, server.passcode, server.lobbyId, result =>
{
var status = result.status;
console.log(status + " : " + JSON.stringify(result, null, 2));
});
void successCallback(Map<String, dynamic>? jsonResponse) {
// Did connect.
// Your code
}
void failureCallback(Map<String, dynamic>? jsonError) {
dynamic errorMap = (jsonError is String) ? json.decode(jsonError) : jsonError;
// Your code
}
// data is retrieved from the onLobby event ROOM_ASSIGNED here.
RelayConnectOptions connectOptions = RelayConnectOptions(
false,
data["connectData"]["address"],
data["connectData"]["ports"]["ws"],
data["passcode"],
data["lobbyId"]);
ServerResponse result = await _bc.relayService.connect(eRelayConnectionType:RelayConnectionType.WEBSOCKET, options:connectOptions, onSuccess:successCallback, onFailure:failureCallback);
-- options come from the lobby ROOM_ASSIGNED event
local options = {
host = data.connectData.address,
port = data.connectData.ports.ws,
ssl = false,
passcode = data.passcode,
lobbyId = data.lobbyId
}
local successCallback = function(response)
-- connected
end
local failureCallback = function(response)
-- your code
end
_bc.relay:connect(options, successCallback, failureCallback)
N/A
-- `room` is the data of the lobby ROOM_READY event (see registerRTTLobbyCallback).
local connectionType = _bc.relay.ConnectionType.UDP
local options = {
host = room.connectData.address,
port = room.connectData.ports.udp,
passcode = room.passcode,
lobbyId = room.lobbyId
}
local onSuccess = function(message)
print("Connected to relay server")
end
local onFailure = function(message)
print("Relay connection failed | " .. tostring(message))
end
_bc.relay:connect(connectionType, options, onSuccess, onFailure)
// N/A
// N/A