Geekzone: technology news, blogs, forums
Guest
Welcome Guest.
You haven't logged in yet. If you don't have an account you can register now.


saguna

8 posts

Wannabe Geek


#9561 27-Sep-2006 10:19
Send private message

Hi,

Im running a java bluetooth server on my laptop using avetana bluetooth api and have a client that i have installed on
a Motorola Razor V3i. My client is not able to discover the services. It returns the message Unable to find service!

Can someone please help me with this problem?

regards
Saguna.

The server code looks like:


import java.io.InputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
//import java.lang.*;
import java.io.IOException;
import javax.bluetooth.*;
//import javax.bluetooth.UUID;
import javax.microedition.io.Connector;
import javax.microedition.io.StreamConnection;
import javax.microedition.io.StreamConnectionNotifier;

public class blueconn {
public static final UUID uuid = new UUID(
"27012f0c68af4fbf8dbe6bbaf7ab651b", false);

public blueconn() {
try {

LocalDevice local = LocalDevice.getLocalDevice();
if(!local.setDiscoverable(DiscoveryAgent.GIAC)) {
System.out.println("failed to Set Discoverable");
// f.append("Failed to change to the dicoverable mode");
return;

}
System.out.println("Set Discoverable");
StreamConnectionNotifier server = (StreamConnectionNotifier) Connector
.open("btspp://localhost:"
+ uuid
//+ ";name="
//+ name
//+ ";authorize=false;authenticate=false;encrypt=false"
);
System.out.println("connecting...");
StreamConnection conn = server.acceptAndOpen();

// Open the input to read data from
InputStream in = conn.openInputStream();
ByteArrayOutputStream out = new ByteArrayOutputStream();

// Read the data sent from the client until the end of stream
int data;
while((data = in.read()) != -1){
out.write(data);
}
System.out.println("Data Read");

System.out.println(out.toString());

// Close all open resources
in.close();
conn.close();
server.close();

} catch (IOException e) {
e.printStackTrace();
}
}

public static void main(String[] args) {
new blueconn();

}
}


and the Client code looks like:

/*
* HelloClient.java
*
* Created on 20 September 2006, 01:48
*/

package messagepassing;

import java.lang.*;
import java.io.*;
import javax.microedition.io.*;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.bluetooth.*;

/**
*
* @author Saguna
* @version
*/
public class HelloClient extends BluetoothMIDlet {

/**
* Connects to the server and sends 'Hello, World'
* to the server.
*/

public void run() {

// Creates the Form and adds the Exit Command to it
Form f = new Form("Client");
f.addCommand(new Command("Exit", Command.EXIT, 1));
f.setCommandListener(this);
Display.getDisplay(this).setCurrent(f);
try {

// Retrieve the connection string to connect to the server
LocalDevice local = LocalDevice.getLocalDevice();
DiscoveryAgent agent = local.getDiscoveryAgent();

String connString = agent.selectService (
new UUID("27012f0c68af4fbf8dbe6bbaf7ab651b", false),
ServiceRecord.NOAUTHENTICATE_NOENCRYPT, false);
if (connString != null){

try {
//Connect to the server and send 'Hello World'
StreamConnection conn = (StreamConnection)
Connector.open(connString);
OutputStream out = conn.openOutputStream();
out.write("Hello, World".getBytes());
out.close();
conn.close();

f.append("Message sent correctly");

} catch (IOException e) {
f.append("IOException: ");
f.append(e.getMessage());
}
} else {
// Unable to locate a service so just print an error message
// on the screen
f.append("Unable to locate service");
}

} catch (BluetoothStateException e){
f.append("BluetoothStateException: ");
f.append(e.getMessage());

}
}
}



Create new topic
JAMMAN2110
872 posts

Ultimate Geek
+1 received by user: 4

Trusted

  #47013 28-Sep-2006 09:11
Send private message

Is bluetooth set to discoverable?



freitasm
BDFL - Memuneh
80652 posts

Uber Geek
+1 received by user: 41045

Administrator
ID Verified
Trusted
Geekzone
Lifetime subscriber

#47031 28-Sep-2006 11:23
Send private message

And are the services enabled?





Referral links: Quic Broadband (free setup code: R587125ERQ6VE) | Samsung | AliExpress | Wise | Sharesies 

 

Support Geekzone by subscribing (browse ads-free), or making a one-off or recurring donation through PressPatron.

 


saguna

8 posts

Wannabe Geek


#47183 30-Sep-2006 02:42
Send private message

ya bluetooth is set to discoverable and services are enabled! Infact there is just one service that is represented by the UUID!
Can someone plz plz help me out! Its drivin me a little crazy now!

All ur help is really appreciated!




saguna

8 posts

Wannabe Geek


#47360 3-Oct-2006 03:48
Send private message

hey guys,



im still looking for help on this! I tried communicatin between two laptops using two BT dongles,

i am able to discover the service but it seems my client is not able to make a connection to my server.



Can someone please help!!



thanks!

Create new topic








Geekzone Live »

Try automatic live updates from Geekzone directly in your browser, without refreshing the page, with Geekzone Live now.



Are you subscribed to our RSS feed? You can download the latest headlines and summaries from our stories directly to your computer or smartphone by using a feed reader.