This week's book giveaway is in the Security forum.
We're giving away four copies of Securing DevOps and have Julien Vehent on-line!
See this thread for details.
Win a copy of Securing DevOps this week in the Security forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

J2ME Bluetooth - more then one host prolem  RSS feed

Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have not so simple question concerning J2ME and Bluetooth in terms of examples that can be found on the net and situation with several hosts and one client.
Most of examples that I was able to find on the net works fine on simulator (I am using NetBeans 6.1) but not on the real device. I think the reason is simple - in most cases in "servicesDiscovered()" method I have an entry like shown below (I am posting only the most relevant parts of the code):

public void servicesDiscovered(int transID, ServiceRecord[] records) {

for (int i = 0; i < records.length; i++) {
m_strUrl = records[i].getConnectionURL(ServiceRecord.AUTHENTICATE_ENCRYPT, false);

if (m_strUrl.startsWith("btspp")) //we have found our service protocol
m_bServerFound = true;

and then in serviceSearchCompleted() method we are trying to establish a connection like this:

public void serviceSearchCompleted(int arg0, int arg1) {
if (m_bServerFound) {
try { //lets the communication start by setting the url and send client reponse

m_StrmConn = (StreamConnection);

m_Output = m_StrmConn.openOutputStream();
m_Input = m_StrmConn.openInputStream();


} catch (IOException ex) {

Like I said before, such a solution works fine on simulator, but not on real life. On real life during device/service discovery, a number of them can be found. And proposed servicesDiscovered() method takes the first one that satisfies the protocol requirenment. Of course I could discover a services by UUID but that won't resolve my problem neither, because I can imagine that there will be several apps with the same UUID started on more then one mobile.

Let's imagine the follwing situation - I have a J2ME Bluetooth chat application and three mobiles - mA, mB and mC.
On mA and mB I start my chat midlet and I set it to work as hosts.
On mC I start my chat midlet and set it to work as a client (I want them to connect to a host).And I would like my client's part of a chat midlet to tell me that two hosts were found (one on mA and one on mB) - it can be shown as choiceList or something similar. And then, after choosing the proper host, the connection will be established.

Or maybe simpler use case - a J2ME Bluetooth Echo application.
Once again - I set up mA and mB to work as hosts and then I want mC to connect to one of the hosts. And I have to be able to differentiate mA host and mB host.

How should I do this?

I'm not sure if I managed to describe my problem clearly.

Any fragment of source code would be more then welcome.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!