Skip to content
This repository was archived by the owner on Nov 22, 2021. It is now read-only.

BluetoothServer

Víctor Daniel Guevara edited this page Aug 10, 2020 · 10 revisions

This class represents a BluetoothServer that can listen for incoming connections.

public class BluetoothServer: Bluetooth

Method overview

Method Action
SendTo(string, string) Sends the message in the first argument to the device with the address of the second argument
SendToAll(string) Sends the message in the argument to all the devices connected to the server
SetMaxConnections(int) Set the maximum number of connections allowed by the server (can't be more than 5)
Start() Starts a Bluetooth server with the UUID of a serial port and the SDP Service name "BluetoothServer"
Start(string) Starts a Bluetooth server with the UUID of a serial port, and the SDP Service name specified as the argument
Start(string, string) Starts a Bluetooth server with the UUID specified in the first argument and the SDP Service name specified in the second argument
Stop() Stops listening and closes all the connections

Events

BluetoothServer.ServerStateChanged

Raised when the server state changes.

public event EventHandler<ServerStateChangedEventArgs> ServerStateChanged;

ServerStateChangedEventArgs has the following fields:

  • ServerState state: the new state of the server. Possible values are ServerState.LISTENING, ServerState.NOT_LISTENING, ServerState.STOPPED.

BluetoothServer.ClientConnected

Raised when a client connects to the server.

public event EventHandler<DeviceInfoChangedEventArgs> ClientConnected;

DeviceStateChangedEventArgs has the following fields:

  • BluetoothDevice Device: the device of the client that connected.

BluetoothServer.ClientDisconnected

Raised when a client disconnects to the server.

public event EventHandler<DeviceInfoChangedEventArgs> ClientDisconnected;

Methods

BluetoothServer.SetMaxConnections(int)

Set the maximum number of connections allowed by the server. If the argument is more than 5, it will be ignored and 5 will be used instead.

public void SetMaxConnections(int)

BluetoothServer.SendTo(string, string)

Sends the message in the second argument to the device with the address of the first argument.

public void SendTo(string address, string message)

BluetoothServer.SendToAll(string)

Sends the message in the argument to all the devices connected to the server.

public void SendToAll(string)

BluetoothServer.Start()

Starts a Bluetooth server with the UUID of a serial port and the SDP Service name "BluetoothServer".

public void Start()

BluetoothServer.Start(string)

Starts a Bluetooth server with the UUID of a serial port, and the SDP Service name specified as the argument.

public void Start(string)

BluetoothServer.Start(string, string)

Starts a Bluetooth server with the UUID specified in the first argument and the SDP Service name specified in the second argument

public void Start(string, string)

BluetoothServer.Stop()

Closes the server socket from listening and closes all the current connections.

public void Stop()

Constants

BluetoothServer.COULD_NOT_LISTEN

A message sent to the Server Object indicating that the server could not open a socket to listen for incoming connections.

public const string COULD_NOT_LISTEN = "server.error.COULD_NOT_LISTEN";

BluetoothServer.COULD_NOT_CONNECT

A message sent to the Server Object indicating that the server could not accept an incoming connection.

public const string COULD_NOT_CONNECT = "server.error.COULD_NOT_CONNECT";

BluetoothServer.NOT_LISTENING

A message sent to the Server Object indicating that the server is not listening for incoming connections anymore.

public const string COULD_NOT_CONNECT = "server.not_listening";