org.opennfc.p2p
Interface P2PConnectionLess


public interface P2PConnectionLess

This interface exposes the methods for the P2P connectionless. Use P2PManager.createP2PConnectionLess(java.lang.String, byte) to create a new instance of P2P connectionless.

Since:
Open NFC 4.1

Method Summary
 void cancel()
          Cancels every pending operation.
 void close()
          Closes a pending connectionLess.
 byte getLocalSap()
          Retrieves the local Service Access Point value.
 boolean ready()
          Determines if there is a data that can be receive via a call to recvFrom().
 int recvFrom(byte[] data)
          Reads some number of bytes from the P2P connectionless and stores them into the buffer array data.
 int recvFrom(byte[] data, int off, int len)
          Reads up to len bytes of data from the P2P connection into an array of bytes.
 void sendTo(byte sap, byte[] data)
          Sends data.length bytes from the specified byte array through a connectionless transport.
 void sendTo(byte sap, byte[] data, int off, int len)
          Sends len bytes from the specified byte array starting at offset off through a connectionless transport.
 

Method Detail

getLocalSap

byte getLocalSap()
                 throws IOException,
                        NfcException
Retrieves the local Service Access Point value.

Throws:
IOException - if the connection is not connected.
NfcException - if a NFC error occurred.
Since:
Open NFC 4.1

sendTo

void sendTo(byte sap,
            byte[] data)
            throws IOException
Sends data.length bytes from the specified byte array through a connectionless transport. The general contract for sendTo(data) is that it should have exactly the same effect as the call sendTo(data, 0, data.length).

Parameters:
sap - the remote SAP value. Valid range is 2..63.
data - the buffer containing the data to be sent.
Throws:
IllegalStateException - if the connection is not open or if another write operation is pending.
IllegalArgumentException - if the data buffer is null.
IOException - if an error occurs during the communication with the peer device, or if cancel() is called before the write operation is completed, or if the peer device closed the connection before receiving the data.
Since:
Open NFC 4.1

sendTo

void sendTo(byte sap,
            byte[] data,
            int off,
            int len)
            throws IOException
Sends len bytes from the specified byte array starting at offset off through a connectionless transport.

If data is null, a NullPointerException is thrown.

If off is negative, or len is negative, or off+len is greater than the length of the array b, then an IndexOutOfBoundsException is thrown.

Parameters:
sap - the remote SAP value. Valid range is 2..63.
data - the buffer containing the data to be sent.
off - the start offset in byte of the data in the buffer.
len - the number of bytes to write.
Throws:
IllegalStateException - if the connection is not open or if another write operation is pending.
IllegalArgumentException - if the data buffer is null or if offset or length are negative.
IndexOutOfBoundsException - if the off or len are outside of the data buffer.
IOException - if an error occurs during the communication with the peer device, or if cancel() is called before the write operation is completed, or if the peer device closed the connection before receiving the data.
Since:
Open NFC 4.1

recvFrom

int recvFrom(byte[] data)
             throws IOException
Reads some number of bytes from the P2P connectionless and stores them into the buffer array data. The number of bytes actually read is returned as an integer.

The remote Service Access Point (SAP) is be stored in a byte at the end of the data buffer array. The length returned by recvFrom() does not include this byte.

This method blocks until input data is available, or an exception is thrown.

Returns:
the total number of bytes read into the buffer, or -1 if there is no more data.
Throws:
IllegalStateException - if the connection is not open or if another read operation is pending.
IllegalArgumentException - if the data buffer is null.
IOException - if an error occurs during the communication with the peer device or if cancel() is called before the read operation is completed.
Since:
Open NFC 4.1

recvFrom

int recvFrom(byte[] data,
             int off,
             int len)
             throws IOException
Reads up to len bytes of data from the P2P connection into an array of bytes. An attempt is made to read as many as len bytes, but a smaller number may be read, possibly zero. The number of bytes actually read is returned as an integer.

The remote Service Access Point (SAP) is be stored in a byte at the end of the data buffer array. The length returned by recvFrom() does not include this byte.

This method blocks until input data is available, or an exception is thrown.

If data is null, a NullPointerException is thrown.

If off is negative, or len is negative, or off+len is greater than the length of the array b, then an IndexOutOfBoundsException is thrown.

If len is zero, then no bytes are read and 0 is returned; otherwise, there is an attempt to read at least one byte. If no byte is available , the value -1 is returned; otherwise, at least one byte is read and stored into data.

Returns:
the total number of bytes read into the buffer, or -1 if there is no more data.
Throws:
IllegalStateException - if the connection is not open or if another read operation is pending.
IllegalArgumentException - if the data buffer is null or if offset or length are negative.
IndexOutOfBoundsException - if the off or len are outside of the data buffer.
IOException - if an error occurs during the communication with the peer device or if cancel() is called before the read operation is completed.
Since:
Open NFC 4.1

ready

boolean ready()
              throws IOException
Determines if there is a data that can be receive via a call to recvFrom(). If true, a call to recvFrom() will not block the application.

Returns:
true if there is data to read; false if there is no data to read
Throws:
IOException - if connection to the target is lost or it has been closed.
Since:
Open NFC 4.1

cancel

void cancel()
Cancels every pending operation.

Since:
Open NFC 4.1

close

void close()
           throws IOException
Closes a pending connectionLess.

Throws:
IOException - if the connectionLess is broken.
Since:
Open NFC 4.1

Copyright © 2010-2011 Inside Secure
Except as noted, this content is licensed under Apache 2.0 License.