This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Bluetooth Question  RSS feed

 
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to run a bluetooth code (from Jonathan knudsen book) from sony ericsson cell phones (W550i & K750i).

Same code is run on both cell phones.

The structure of code is like this(same code in both phones):
1) A server which is created first & waits for client connection
2) Client on each then should connect to Server at the other cell phone & both will achieve some thing.
3) seperate thread for client & server


server part is working as expected where as at client part selectService() method is not finding the service at the other end.

Client thread:

public void run() {
// this is the BT client portion of the dating service
try {
mDiscoveryAgent = LocalDevice.getLocalDevice().getDiscoveryAgent();
} catch (Exception ex) {
}

StreamConnection conn = null;
DataOutputStream dos = null;
while( !mEndNow) {
try {
mDateConnect = mDiscoveryAgent.selectService(DATING_SERVICE_ID,
ServiceRecord.NOAUTHENTICATE_NOENCRYPT, false);

if (mDateConnect != null) {
conn = (StreamConnection) Connector.open(mDateConnect);
dos = conn.openDataOutputStream();
dos.writeUTF(mPref);
dos.writeUTF(mHeight);
dos.writeUTF(mContact);
dos.flush();
dos.close();
}

} catch (Exception ex) {
}
}
}

Server Thread:

public void run() {

try {
// get local BT manager
mLocalBT = LocalDevice.getLocalDevice();

// set we are discoverable
mLocalBT.setDiscoverable(DiscoveryAgent.GIAC);
String url = "btspp://localhost:" + DATING_SERVICE_ID.toString() +
";name=Dating Service;authorize=false";

// create notifier now
mServerNotifier = (StreamConnectionNotifier) Connector.open(
url.toString());
//System.out.println(" got notifier ");

} catch (Exception e) {
System.err.println("Can't initialize bluetooth: " + e);
}
StreamConnection conn = null;
while (!mEndNow) {
conn = null;

try {
conn = mServerNotifier.acceptAndOpen();
} catch (IOException e) {

continue;
}


// System.out.println(" got a connection!");
if (conn != null)
processRequest(conn);
}

}

What might be the problem?
 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello Girish,

I think you are not specifying the service name correctly, and i suggest that just to check that this is not the case, you should use the service discovery on the client side to find all the service name, store them somewhere and try to connect to them

like , just run a single BT server, the service search will yield only one result, and you should use that to connect to the server

hope this helps
 
Girish Nagaraj
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Faraz,

executed the code in the wireless tool kit.,absolutely no issues.
But when I execute it on the real phone problem starts.

Some times it work, really, most of the times it won't!!!
I think bluetooth connection is not stable..,
 
ranger
Sheriff
Posts: 17314
11
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check my response to this thread here
http://www.coderanch.com/t/230227/JME/Mobile/Bluetooth-Application

Phones are notorious for not exactly implementing the spec correctly. I don't know specifically about that phone, but the emulator does implement the spec correctly.

Mark
 
Girish Nagaraj
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Mark..
 
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!