I'm currently making my first steps with the Nokia 6131 NFC / J2ME programming. I'm trying to create a program that is able to enumerate remote devices in range. Therefore I use the TargetListener pattern as described in various posts and examples. That works just fine, I add the TargetListener to the DiscoveryManager for a given amount of time and remove it afterwards. All discovered devices are recorded meantime. I hope this is the correct way to do this.
Afterwards (or before that, that shouldn't matter, or am I wrong?) I try to detect a remote peer-to-peer device and that's where my problems start: I can only determine if there is a remote device by trying to establishing a connection, as far as i know. But because the function call to establish the connection is blocking and doesn't offer a timeout mechanism, I've to put it into a thread. So I start the thread, wait for a given amount of time and and check if the thread detected the remote device. If so, I close the connection and every thing's just fine. But what if there is no remote device? My thread is blocked (for ever?) and the main program has to abort the thread somehow. At the moment I do this by setting the thread-variable holding the instance of the thread to null and this works. Although I'm new to Java programming, it seems like a terribly wrong way to do this. My question: How to abort the blocking function call to establish a peer-to-peer connection after a given amount of time without violating the paradigms of the Java programming language and without leaving the NFC connection object in an undefined state.
Another question: Is it possible to get the (random) UID used for an peer-to-peer connection?
I hope I explained my problem well enough, if not so, feel free to post questions. I can also post Java code if required.