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.


8 posts

Wannabe Geek


Topic # 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
871 posts

Ultimate Geek

Trusted

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

Is bluetooth set to discoverable?

BDFL - Memuneh
60996 posts

Uber Geek
+1 received by user: 11837

Administrator
Trusted
Geekzone
Lifetime subscriber



8 posts

Wannabe Geek


Reply # 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!




8 posts

Wannabe Geek


Reply # 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

Twitter »

Follow us to receive Twitter updates when new discussions are posted in our forums:



Follow us to receive Twitter updates when news items and blogs are posted in our frontpage:



Follow us to receive Twitter updates when tech item prices are listed in our price comparison site:





News »

Targus set sights on enterprise and consumer growth in New Zealand
Posted 13-Aug-2018 13:47


Huawei to distribute nova 3i in New Zealand
Posted 9-Aug-2018 16:23


Home robot Vector to be available in New Zealand stores
Posted 9-Aug-2018 14:47


Panasonic announces new 2018 OLED TV line up
Posted 7-Aug-2018 16:38


Kordia completes first live 4K TV broadcast
Posted 1-Aug-2018 13:00


Schools get safer and smarter internet with Managed Network Upgrade
Posted 30-Jul-2018 20:01


DNC wants a safer .nz in the coming year
Posted 26-Jul-2018 16:08


Auldhouse becomes an AWS Authorised Training Delivery Partner in New Zealand
Posted 26-Jul-2018 15:55


Rakuten Kobo launches Kobo Clara HD entry level reader
Posted 26-Jul-2018 15:44


Kiwi team reaches semi-finals at the Microsoft Imagine Cup
Posted 26-Jul-2018 15:38


KidsCan App to Help Kiwi Children in Need
Posted 26-Jul-2018 15:32


FUJIFILM announces new high-performance lenses
Posted 24-Jul-2018 14:57


New FUJIFILM XF10 introduces square mode for Instagram sharing
Posted 24-Jul-2018 14:44


OPPO brings advanced technology to the smartphone market with new device
Posted 24-Jul-2018 09:20


Hawaiki Transpacific cable ready-for-service
Posted 20-Jul-2018 11:29



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.

Alternatively, you can receive a daily email with Geekzone updates.