473,625 Members | 3,251 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I send a message to a bluetooth device?

108 New Member
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 1570

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

Similar topics

1
1634
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 "bluetooth device not found". I don't use bluetooth at all in my program. Any ideas on how to fix this??
1
6083
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 icq or msn messenger? Many thanks for your assistance.
3
5660
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
1663
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); HELPINFO helpInfo = new HELPINFO(); helpInfo.iContextType = HELPINFO_WINDOW;
1
4515
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 it does not work. Would appreciate any help on this. Thanks in advance
7
13968
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 this purpose. For this I registered an object on Service side for Remoting purposes. Remote Object exposes a function named ReloadFiles() that should internally send a message to service class to Reload some files. Now I don't know how to send...
2
1988
by: ad | last post by:
How can I send message to cellular phone by program?
5
2248
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 and tell how to send message from mobile to PC.My paltform is VC++.NET
2
19598
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 a bluetooth-capable computer). All I want it to be able to do is allow the phone/computer to read the light level measured by the light sensor and turn the lights on the device on and off. Does anyone have any idea where I should start? I'm...
0
912
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
8256
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8694
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8635
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8356
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8497
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6118
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5570
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4089
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2621
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 we have to send another system

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.