473,473 Members | 1,808 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Has anyone ever faced any prob connect to a bluetooth service using j2me?

108 New Member
I 've been trying to connect to a bluetooth service using j2me but I am getting a null exception..The client is able to identify devices in the nearby regions but not being able to connect to their service.I am pasting my codes and would be highly obliged if any1 could tell me the reason and if the codes are correct..

Expand|Select|Wrap|Line Numbers
  1.  
  2. //Server
  3. public  void startServer() {
  4.  
  5.         System.out.println("server is running...");
  6.                 UUID uuid = new UUID("1101", true);
  7.                 String connectionString = "btspp://localhost:" + uuid +";name=Server";
  8.         try {
  9.             // create a server connection
  10.             StreamConnectionNotifier notifier =(StreamConnectionNotifier) Connector.open(connectionString);
  11.             // accept client connections
  12.             StreamConnection connection = notifier.acceptAndOpen();
  13.  
  14.                     LocalDevice localDevice = LocalDevice.getLocalDevice();
  15.                     stringItem.setText(localDevice.getFriendlyName()+" : "+localDevice.getBluetoothAddress());
  16.                     System.out.println("Address: "+localDevice.getBluetoothAddress());
  17.  
  18.                     System.out.println("Name: "+localDevice.getFriendlyName());
  19.  
  20.             // prepare to send/receive data
  21.             byte buffer[] = new byte[100];
  22.             String msg = "hello there, client";
  23.             InputStream is = connection.openInputStream();
  24.             OutputStream os = connection.openOutputStream();
  25.             // send data to the client
  26.             os.write(msg.getBytes());
  27.             // read data from client
  28.             is.read(buffer);
  29.                     int len = is.available();
  30.  
  31.                     stringItem.setText(Integer.toString(len));
  32.             connection.close();
  33.         } catch(IOException e) {
  34.           e.printStackTrace();
  35.         }
  36.  
  37.     }
  38.  
  39.  
  40.  
  41.  
  42.  
  43. //Client
  44. private void deServiceSearch(RemoteDevice device) {
  45.         //int[] attr={10203040607040A1B1C1DE100};
  46.     System.out.println("TEst4..");
  47.         setError("2");
  48.         UUID[] uuids = new UUID[1];
  49.         uuids[0] = new UUID(1101);
  50.  
  51.  
  52.         try {
  53.  
  54.             System.out.println("TEst6..");
  55.  
  56.             UUID[] uuidSet = new UUID[1];
  57.  
  58.             uuidSet[0]=new UUID("1101",false);
  59.  
  60.             System.out.println("\nSearching for service...");
  61.             setError("3");
  62.             agent.searchServices(null,uuidSet,device,this);
  63.  
  64.         } catch (BluetoothStateException ex) {
  65.             setError("4");
  66.         }
  67.     }
  68.  
  69.  
  70.  
  71.  
Apr 2 '11 #1
1 1928
Stefaan Ghysels
3 New Member
I think you have a mistake here :

// prepare to send/receive data
byte buffer[] = new byte[100];
Dec 11 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Dave Rathnow | last post by:
We are looking at using J2ME in a embedded device that will be deployed in an industrial application and I've been doing some research to see how practical J2ME would be for our application. Most...
27
by: garyolsen | last post by:
In C++ what kind of unexpected conditions should be handled as exceptions? Besides dividing by 0, bad memory allocation, what're the most popular exceptions? When should not use exception,...
0
by: TM | last post by:
Greetings, I've more or less figured out how to get a list of users who have access to a particular mailbox (code below), but I'm stumped as to how to get a list of mailboxes that a particular user...
0
by: JDF | last post by:
I am trying to create a Windows service using SimpleXMLRPCServer and win32serviceutil. The service itself seems to be working properly (starts, stops, etc) and I can connect using an XMLRPC client...
1
by: Al Wilkerson | last post by:
Hey, Has anyone ever used InstallSheild to create a install/setup package for a ..net service? If so, did you just create the component service and enable the use of the ..Net Class and/or...
1
by: dileep | last post by:
Hi I want to call a web service using AJAX and SOAP.I have tried some approaches but am not able to do so and am unsuccessful.Has anyone tried with AJAX to connect web services??Can anyone suggest a...
3
by: =?Utf-8?B?RGFuZGFuIFpoYW5n?= | last post by:
Now I have a web application, a web service and a SQL Server database. The Web application will invoke the web service, the web service invokes the SQL Server stored procedure. I let the web...
0
by: jordo | last post by:
I have an asp.Net app that connects to the WSS 2.0 list web service. I'm having issues with IIS and .Net configurations and hope that someone can help me. My ideal configuration is: asp.net:...
0
by: mailsamin | last post by:
Hi, I want to call an asp.net web service from j2me client. Can someone give any info on this? Thanks Manisha
1
by: neveen | last post by:
i want to open and read text file using j2me that can run on mobile 6630 then i want to make button called read that when pressed the data inside text display
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.