javax.bluetooth
Interface L2CAPConnection


public interface L2CAPConnection
extends javax.microedition.io.Connection

The L2CAPConnection interface represents a connection-oriented L2CAP channel. This interface is to be used as part of the CLDC Generic Connection Framework.

To create a client connection, the protocol is btl2cap. The target is the combination of the address of the Bluetooth device to connect to and the Protocol Service Multiplexor (PSM) of the service. The PSM value is used by the L2CAP to determine which higher level protocol or application is the recipient of the messages the layer receives.

The parameters defined specific to L2CAP are ReceiveMTU (Maximum Transmission Unit (MTU)) and TransmitMTU. The ReceiveMTU and TransmitMTU parameters are optional. ReceiveMTU specifies the maximum payload size this connection can accept, and TransmitMTU specifies the maximum payload size this connection can send. An example of a valid L2CAP client connection string is:
btl2cap://0050CD00321B:1003;ReceiveMTU=512;TransmitMTU=512


Field Summary
static int DEFAULT_MTU
          Default MTU value for connection-oriented channels is 672 bytes.
static int MINIMUM_MTU
          Minimum MTU value for connection-oriented channels is 48 bytes.
 
Method Summary
 int getReceiveMTU()
          Returns the ReceiveMTU that the connection supports.
 int getTransmitMTU()
          Returns the MTU that the remote device supports.
 boolean ready()
          Determines if there is a packet that can be read via a call to receive().
 int receive(byte[] inBuf)
          Reads a packet of data.
 void send(byte[] data)
          Requests that data be sent to the remote device.
 
Methods inherited from interface javax.microedition.io.Connection
close
 

Field Detail

DEFAULT_MTU

public static final int DEFAULT_MTU
Default MTU value for connection-oriented channels is 672 bytes.

The value of DEFAULT_MTU is 0x02A0 (672).


MINIMUM_MTU

public static final int MINIMUM_MTU
Minimum MTU value for connection-oriented channels is 48 bytes.

The value of MINIMUM_MTU is 0x30 (48).

Method Detail

getTransmitMTU

public int getTransmitMTU()
                   throws java.io.IOException
Returns the MTU that the remote device supports. This value is obtained after the connection has been configured. If the application had specified TransmitMTU in the Connector.open() string then this value should be equal to that. If the application did not specify any TransmitMTU, then this value should be less than or equal to the ReceiveMTU the remote device advertised during channel configuration.
Returns:
the maximum number of bytes that can be sent in a single call to send() without losing any data
Throws:
java.io.IOException - if the connection is closed

getReceiveMTU

public int getReceiveMTU()
                  throws java.io.IOException
Returns the ReceiveMTU that the connection supports. If the connection string did not specify a ReceiveMTU, the value returned will be less than or equal to the DEFAULT_MTU. Also, if the connection string did specify an MTU, this value will be less than or equal to the value specified in the connection string.
Returns:
the maximum number of bytes that can be read in a single call to receive()
Throws:
java.io.IOException - if the connection is closed

send

public void send(byte[] data)
          throws java.io.IOException
Requests that data be sent to the remote device. The TransmitMTU determines the amount of data that can be successfully sent in a single send operation. If the size of data is greater than the TransmitMTU, then only the first TransmitMTU bytes of the packet are sent, and the rest will be discarded. If data is of length 0, an empty L2CAP packet will be sent.
Parameters:
data - data to be sent
Throws:
java.io.IOException - if data cannot be sent successfully or if the connection is closed
NullPointerException - if the data is null

receive

public int receive(byte[] inBuf)
            throws java.io.IOException
Reads a packet of data. The amount of data received in this operation is related to the value of ReceiveMTU. If the size of inBuf is greater than or equal to ReceiveMTU, then no data will be lost. Unlike read() on an java.io.InputStream, if the size of inBuf is smaller than ReceiveMTU, then the portion of the L2CAP payload that will fit into inBuf will be placed in inBuf, the rest will be discarded. If the application is aware of the number of bytes (less than ReceiveMTU) it will receive in any transaction, then the size of inBuf can be less than ReceiveMTU and no data will be lost. If inBuf is of length 0, all data sent in one packet is lost unless the length of the packet is 0.
Parameters:
inBuf - byte array to store the received data
Returns:
the actual number of bytes read; 0 if a zero length packet is received; 0 if inBuf length is zero
Throws:
java.io.IOException - if an I/O error occurs or the connection has been closed
InterruptedIOException - if the request timed out
NullPointerException - if inBuf is null

ready

public boolean ready()
              throws java.io.IOException
Determines if there is a packet that can be read via a call to receive(). If true, a call to receive() will not block the application.
Returns:
true if there is data to read; false if there is no data to read
Throws:
java.io.IOException - if the connection is closed
See Also:
receive(byte[])