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());
}
}
}