473,386 Members | 1,793 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How do I send a message to a bluetooth device?

108 100+
Using the bluetooth API in j2me, I want to send a message to another mobile phone. I have been able to discover devices and services on the corresponding devices. I have also been able to connect to the services however when I try to send a message from the server to the client. The message is written but the client does not seem to receive it ..

Expand|Select|Wrap|Line Numbers
  1. public void startServer() throws IOException { UUID uuid = new UUID("1101", false); //Create the service url String connectionString = "btspp://localhost:" + uuid + ";name=xyz"; //open server url StreamConnectionNotifier streamConnNotifier = (StreamConnectionNotifier) Connector.open(connectionString); //Wait for client connection System.out.println("\nServer Started. Waiting for clients to connect..."); StreamConnection connection = streamConnNotifier.acceptAndOpen(); RemoteDevice dev = RemoteDevice.getRemoteDevice(connection); System.out.println("Remote device address: " + dev.getBluetoothAddress()); System.out.println("Remote device name: " + dev.getFriendlyName(true)); Survey.setTitle(dev.getFriendlyName(true)); //read string from spp client try { DataInputStream in = connection.openDataInputStream(); OutputStream writer=connection.openDataOutputStream();
  2.  
  3.               String str="";
  4.                 TextField  textfield;
  5.                 for (int i=0;i<questions.size();i++){
  6.                     textfield = (TextField) questions.elementAt(i);
  7.                     str += formatSurvey(textfield,i)+"&";
  8.  
  9.                 }
  10.              writer.write(str.getBytes(), 0, str.getBytes().length);
  11.              writer.flush();
  12.             System.out.println("Written to client "+str);
  13.  
  14.             System.out.println("Reading  "+in.readUTF());
  15.             try {
  16.                 displaySurveyresults(str);
  17.             }
  18.             catch(Exception e){
  19.                 System.out.println(e.getMessage());
  20.             }
  21.               streamConnNotifier.close();
  22.         }
  23.         catch(Exception e){
  24.             System.err.println(e.getMessage());
  25.         }
  26.   }
  27.  
  28. public void servicesDiscovered(int transID, ServiceRecord[] servRecord) { switchDisplayable(null , getList1()); list1.append(servRecord.toString(), null); System.out.println("Service discovered..."+servRecord.toString()); for (int i=0;i
  29.  
  30.             System.out.println("Test2");
  31.             DataInputStream in =  con.openDataInputStream();
  32.             System.out.println("Test3"+in.readUTF());
  33.             //con.openDataOutputStream().write(142);
  34.             System.out.println("Test4   "+in.available());
  35.             byte[] bte=new byte[in.available()];
  36.             System.out.println("Test5  "+bte.length);
  37.             in.read(bte);
  38.             System.out.println("Test6");
  39.             for (int l=0;l<bte.length;l++){
  40.                 System.out.println(bte[i]);
  41.                 System.out.println("Test7");
  42.                 stringItem.setText(stringItem.getText()+1 + bte[i]);
  43.             }
  44.             OutputStream outStream=con.openOutputStream();
  45.             OutputStreamWriter writer = new OutputStreamWriter(outStream);
  46.             writer.write("Vimal");
  47.         } catch (IOException ex) {
  48.             ex.printStackTrace();
  49.         }
  50.  
  51.     }
  52.  
  53.  
  54.  
  55.  
  56.  
  57. }
have I erred somewhere bcause these are codes from the Net?
Apr 4 '11 #1
0 1547

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

Similar topics

1
by: Karl Irvin | last post by:
On some customers computers, my custom menus are overwritten. On a menu with seveal choices, my choices are replaced with a single "Other....." and when this is clicked, a message pops up and says...
1
by: crowl | last post by:
Hi all, I'm looking for a simple c source sample which I can send message to ICQ and MSN Messenger. I have search with google, but without luck on my side. Do you know any doc for programming...
3
by: Eka Gautama | last post by:
Hi all, Is it possible to intercept net send message? I don't want windows show the message to screen directly, but i want process first, then display to the screen... Thanks
0
by: Jerry | last post by:
Hi, I send a message WM_HELP, but it return false. The code is: Point point = new Point(e.X, e.Y); Control child = GetChildAtPoint(point); if (child != null) { point = PointToScreen(point); ...
1
by: Raj | last post by:
Hi, I am trying to send message (WM_CLICK) to a button control in a PowerBuilder application using a C# spy program. This works for all other windows applications but in case of PB application...
7
by: Ahmad Jalil Qarshi | last post by:
Hi! I want to develop two applications one a Windows Service and the other a GUI based application. I want some sort of communication between Service and GUI. I have decided to use Remoting for...
2
by: ad | last post by:
How can I send message to cellular phone by program?
5
by: napster | last post by:
hi, I am working on a project to control some pc activities from mobile but am not able to send a message from mobile to pc.I have tried the AT commands but its not working for me.Can anybody help...
2
by: adamalton | last post by:
Hi, this is probably a bit of a long shot, but I would like to make a simple bluetooth device that just has a couple of lights on it and a light sensor, which can communicate with a mobile phone (or...
0
by: mabiriizihudson | last post by:
how do i track the availability of a bluetooth device in VB.net I am using a USB bluetooth adapter. I want to be able to access a bluetooth device's address in vb.net hudson
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.