Win a copy of Hands On Software Engineering with Python this week in the Jython/Python 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

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
Posts: 17344
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..
 
All of life is a contant education - Eleanor Roosevelt. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!