I wrote two program for phones. One of them has target code,other has initiator codes like as below. Both of them work with normal nfc tags . but still cant connect each other.
Code for Target phone
Code:
public void run() {
NFCIPConnection conn = null;
// Reading state
if (reading) {
// Read while in reading state
while (reading) {
try {
// Start waiting for other phone to initiate connection,
// blocks until connection made or another NFCIP connection
// open called
conn = (NFCIPConnection) Connector.open(TARGET_URL);
// Receive data from connection
byte[] data = conn.receive();
// Send empty message to connection
conn.send(null);
// Append received string to form
form.append(">> " + new String(data) + "\n");
// Close connection
conn.close();
} catch (Exception ex) {
try {
if (conn != null) {
conn.close();
}
}
catch (IOException e) {
}
}
}
Codes for Iniatitor Phone
Code:
while (writing) {
try {
// Try to connect another phone, blocks until connection
// made or another NFCIP connection open called
conn = (NFCIPConnection) Connector.open(INITIATOR_URL);
// Send string from TextBox to connection
conn.send(writeTb.getString().getBytes());
// Receive reply
conn.receive();
// Append sent message to form
form.append("<< " + writeTb.getString() + "\n");
// Close connection
conn.close();
display.setCurrent(form);
read();
}
catch (Exception ex) {
try {
if (conn != null) {
conn.close();
}
} catch (IOException e) {}
}
}