LogicalLabs Bluetooth Module

API Docs for: 1.0.3
Show:

BluetoothSocket Class

Module: Readme

BluetoothSocket objects can be created by calling the createBluetoothSocket method. This is a workaround until TIMOB-13097 is fixed in Titanium.

The permanent solution will be to create these objects by calling the createSocket method on a BluetoothDevice object.

These objects can also be returned in connectionReceived events on BluetoothServerSocket objects.

Methods

cancelConnect

() Void

Available since 1.0.0

Cancels the previously started connection attempt. If there is no connection attempt in progress, it does not do anything.

Returns:

Void:

close

() Void

Available since 1.0.0

Closes the socket.

Returns:

Void:

connect

() Void

Available since 1.0.0

Initiates the connection to the remote device. This is an asynchronous call. Listen for the connected event to be notified when the connection is established.

Returns:

Void:

getReadBufferSize

() Number

Available since 1.0.0

Returns the size of the read buffer in bytes.

Returns:

Number:

Size of the read buffer in bytes.

getRemoteDevice

() BluetoothDevice

Available since 1.0.0

Returns the BluetoothDevice object representing the device to which this socket is connected to.

Returns:

BluetoothDevice:

The object representing the device to which this socket is connected to.

isConnected

() Boolean

Available since 1.0.1

Get the connection status of this socket, ie, whether there is an active connection with remote device.

This function requires API level 14 or higher.

Returns:

Boolean:

True if the socket is connected.

isConnecting

() Boolean

Available since 1.0.0

Returns true if there is a connection attempt in progress, false otherwise.

Returns:

Boolean:

True if there is a connection attempt in progress, false otherwise.

setReadBufferSize

(
  • newReadBufferSize
)
Void

Available since 1.0.0

Sets the size of the read buffer in bytes. You can set the read buffer size at any time, but it will only take effect during the next connection.

Parameters:

  • newReadBufferSize Number

    The desired size of the read buffer in bytes.

Returns:

Void:

write

(
  • buffer
)
Void

Available since 1.0.0

Sends an array of bytes over the socket. Use the Titanium.createBuffer function to create the buffer.

Parameters:

  • buffer Ti.Buffer

    The data to be sent over the socket.

Returns:

Void:

Properties

readBufferSize

Available since 1.0.0

The size of the read buffer in bytes. You can set the read buffer size at any time, but it will only take effect during the next connection.

remoteDevice

BluetoothDevice read-only

Available since 1.0.0

The object representing the device to which this socket is connected to.

Events

connected

Available since 1.0.0

Fired when the connection through the socket is established.

Event Payload:

  • socket BluetoothSocket

    The socket through which the connection was established.

error

Fired when an operation fails.

Event Payload:

  • socket BluetoothSocket

    The socket that experienced the error.

  • errorMessage String

    Description of the error.

receiveData

Event Payload:

  • socket BluetoothSocket

    The socket on which the data was received.

  • data Ti.Buffer