Client API
Events table
Methods table
Events
event OnFinishedInit (BluetoothClient
client, int status, string ErrorMessage)
The event that raised when the Bluetooth client initialization is completed.
In response, the Bluetooth Client status comes and, if there is an error, its error description
(error will be displayed if bluetooth activation is rejected by the user)
Parameters:
BluetoothClient client
The Bluetooth client that raised the event.
int status
Status code. 0 - successful, the others mean an error during
initialization.
string ErrorMessage
Description of the error. If initialization is successful, it will
be empty.
Example:
client.OnFinishedInit += (RaisedClient, status,
ErrorMessage) =>
{
if (status ==
0 && string.IsNullOrEmpty(ErrorMessage))
{
client.StartAdvertising();
}
else
{
Debug.LogError("BluetoothClient failed init. status = " + status + " | Error: " +
ErrorMessage);
}
};
event OnAdvertisingStarted (BluetoothClient
client, int status, string ErrorMessage)
The event that raised at the start of advertising. The response is the status
of the Bluetooth client and, if there is an error, a description of its error.
Parameters:
BluetoothClient client
The Bluetooth client that raised the event.
int status
Status code. 0 - successful, the others mean an error during
initialization.
string ErrorMessage
Description of the error. If initialization is successful, it will
be empty.
Example:
client.OnAdvertisingStarted += (RaisedClient, status,
ErrorMessage) =>
{
if
(status ==
0 && string.IsNullOrEmpty(ErrorMessage))
{
}
else
{
Debug.LogError("BluetoothClient failed AdvertisingStarted. status = " + status + " | Error: " +
ErrorMessage);
}
};
event OnReceivingMessage (string
Message)
Raised when receiving a message from server.
Parameters:
string Message
Received message from server.
Example:
client.OnReceivingMessage += (Message) =>
{
Debug.Log("ReceivingMessage:: " + Message);
};
event OnDisconnected ()
Raised when the client is shutting down.
Example:
client.OnDisconnected += () =>
{
client.Close();
};
Methods
static BluetoothClient CreateClient ()
Creates an instance of BluetoothClient. Important:When
creating an instance of GameObject, DontDestroyOnLoad is used. To avoid this, you can add the
BluetoothClient component via AddComponent<BluetoothClient>();
Example:
BluetoothClient client =
BluetoothClient.CreateClient();
void Init()
Initializing the bluetooth client.
Example:
client.Init();
void StartAdvertising
()
Start of advertising (it is necessary for the server to be able to detect the
device).
Example:
client.StartAdvertising();
void StopAdvertising()
Completion of advertising.
Example:
client.StopAdvertising();
void SendData(string data)
Sending a message to server.
Example:
client.SendData("Some kind of own message");
void Disconnect()
Disconnect the bluetooth client. after completing all procedures, the event OnDisconnected will
be called.
Example:
client.Disconnect();