473,403 Members | 2,270 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,403 software developers and data experts.

trouble connecting client to J2ME server application (JSR-82)

Hello!

Below is the Netbeans Mobility source code for my application (The application offers SPP service, and then just hangs waiting for a client to connect (using acceptAndOpen()). The other device (A7 Engineering's eb506 Bluetooth serial adapter connected to a microcontroller) connects to the phone, but is not linked to my application).

If I make the connection directly from the phone (Nokia 6085) to the eb506, there is no problem connecting and transmitting data - the problem arises when trying to connect from the eb506 to the phone. It is necessary for my application that I connect from the eb506 to the Java server application. Can anyone offer any insight as to why my application is not connecting to the incoming SPP connection from the other device (this is handled in the setupConnections() method). I've been trying down the path of modifying the ServiceRecord with no positive results.

Thanks for your help (If you can help).

Sincerely,

Brum

Expand|Select|Wrap|Line Numbers
  1. import java.io.*;
  2.  
  3. import javax.microedition.midlet.*;
  4. import javax.microedition.lcdui.*;
  5. import javax.microedition.io.*;
  6. import javax.bluetooth.*;
  7.  
  8. /**
  9.  * @author Brum
  10.  */
  11. public class prjMIDlet 
  12.         extends MIDlet implements javax.microedition.lcdui.CommandListener
  13. {
  14.     private Alert safetyAlert = null;
  15.     private Command mExitCommand = new Command("Exit", Command.EXIT,1);
  16.  
  17.     StreamConnectionNotifier notifier = null;
  18.     LocalDevice prjCellPhone = null;
  19.     DataInputStream input;
  20.     UUID myService = new UUID("1101",true);
  21.     String myMIDlet = this.getClass().getName();
  22.     String filter = "*";        
  23.  
  24.     public void startApp() {
  25.         initialize();            // Initialize the safetyAlert interface 
  26.  
  27.         try {
  28.             input = setupConnections(); // Connect the cell phone to the eb506 (create input stream from other device)
  29.         } catch (BluetoothStateException ex) {
  30.             ex.printStackTrace();
  31.         } catch (ClassNotFoundException ex) {
  32.             ex.printStackTrace();
  33.         } catch (IOException ex) {
  34.             ex.printStackTrace();
  35.         }
  36.         Display.getDisplay(this).setCurrent(safetyAlert);   // display the Alert
  37.  
  38.  
  39.         try {
  40.             do {
  41.                 safetyAlert.setString(getMessage(input)); // get incoming message and put it into safetyAlert
  42.                 Display.getDisplay(this).setCurrent(safetyAlert);   // display the Alert with the new message
  43.             } while ((safetyAlert.getString()).length() > 1); // with only a carraige return, no more messages
  44.         } catch (IOException ex) {
  45.             ex.printStackTrace();
  46.         }
  47.  
  48.  
  49.         try {
  50.             PushRegistry.registerConnection(new String("btspp://localhost:" 
  51.                     + myService.toString()), myMIDlet, filter); // Register this connection in the PushRegistry for auto start-up
  52.         } catch (ClassNotFoundException ex) {
  53.             ex.printStackTrace();
  54.         } catch (IOException ex) {
  55.             ex.printStackTrace();
  56.         }
  57.  
  58.         // This next section will set the Alert to display the registered PushRegistry connections
  59.         String[] connectionList = PushRegistry.listConnections(false);
  60.         int listcount = connectionList.length; 
  61.         StringBuffer connlist = new StringBuffer("Connections (# = "+listcount+"):");
  62.         while(listcount > 0){
  63.             connlist.ensureCapacity(connlist.length()+30);
  64.             connlist.append(connectionList[listcount-1]);
  65.             listcount--; 
  66.         }
  67.         safetyAlert.setString(new String(connlist));
  68.         Display.getDisplay(this).setCurrent(safetyAlert);   // display the Alert
  69.  
  70.     }
  71.  
  72.     private void initialize() {
  73.  
  74.     safetyAlert = new Alert("Incoming message: ", "Please Wait...",null,null);
  75.     safetyAlert.setTimeout(Alert.FOREVER);
  76.     safetyAlert.addCommand(mExitCommand);
  77.     safetyAlert.setCommandListener(this);
  78.     return;
  79.     }
  80.  
  81.     public DataInputStream setupConnections() throws BluetoothStateException, IOException, ClassNotFoundException {
  82.  
  83.         prjCellPhone = LocalDevice.getLocalDevice();
  84.  
  85.         prjCellPhone.setDiscoverable(DiscoveryAgent.GIAC);
  86.         notifier = (StreamConnectionNotifier)Connector.open("btspp://localhost:" + myService.toString()); 
  87.  
  88.         safetyAlert.setString("waiting for connection");
  89.         Display.getDisplay(this).setCurrent(safetyAlert);   // display the Alert
  90.  
  91.         /* This next line is where the application stalls, waiting for a client
  92.          * to connect.  I connect with my other device and it is able to connect
  93.          * to the phone, but is not linked to this application */
  94.         StreamConnection sconn = notifier.acceptAndOpen();
  95.  
  96.         /* If I connect with this section of code instead, (connect from phone 
  97.          * directly to my other device), there is no problem with transmitting 
  98.          * data (But the application does not auto-start when the incoming SPP
  99.          * connection occurs.
  100.         DiscoveryAgent prjAgent = prjCellPhone.getDiscoveryAgent();
  101.         String connString = prjAgent.selectService(myService, ServiceRecord.NOAUTHENTICATE_NOENCRYPT, false);                    
  102.         StreamConnection sconn = (StreamConnection)Connector.open(connString);
  103.         input = sconn.openDataInputStream();*/
  104.  
  105.  
  106.         safetyAlert.setString("client device connected");
  107.         Display.getDisplay(this).setCurrent(safetyAlert);   // display the Alert
  108.         return sconn.openDataInputStream();                
  109.     }
  110.  
  111.  
  112.     /* This method gets an ASCII message from the input stream and converts it 
  113.      * to a UniCode string and returns the Unicode string */
  114.     public String getMessage(DataInputStream d) throws IOException {
  115.  
  116.         StringBuffer strBuff = new StringBuffer();
  117.         char store = 0;
  118.         int count = 0;
  119.  
  120.         while (count < 32) {        // maximum message length is 32 characters
  121.             count++;
  122.             store = (char) d.readByte();  // read the next byte of the stream and store as a char
  123.             if (store == 0x000D)
  124.                 break;
  125.             strBuff.append(store);
  126.         }
  127.         return strBuff.toString();
  128.     }
  129.  
  130.  
  131.     public void pauseApp() {
  132.     }
  133.  
  134.     public void destroyApp(boolean unconditional) {
  135.     }
  136.  
  137.     public void commandAction(javax.microedition.lcdui.Command command, javax.microedition.lcdui.Displayable displayable) {
  138.         if (displayable == safetyAlert) {
  139.             if (command == mExitCommand) {
  140.                 Display.getDisplay(this).setCurrent(null);
  141.                 destroyApp(true);
  142.                 notifyDestroyed();
  143.             }
  144.         }
  145.     }
  146. }
  147.  
Oct 3 '08 #1
0 2386

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

Similar topics

0
by: Wole | last post by:
I'm working on a project that requires a Web GUI connected to a server backend application. When a user clicks a button on the GUI the Web client sends a message to the server application which...
0
by: jeff | last post by:
Hiya I want to create 2 "simple" perl scripts, One of them takes a string input on the Com port and then sends it via the internet to a website, The website has a Cgi-Bin and this recieves the...
4
by: BravesCharm | last post by:
I am trying to connect to SQL Server 2005 Express with Visual C# 2005 Express using this code: static void Main(string args) { SqlConnection conn = new SqlConnection(@"Data...
3
by: GTDriver | last post by:
I'm trying to connect my application with a web service located on my own web server(localhost). I guess when the solution/proect is built it makes a file called 'Web...
0
by: Bob | last post by:
I am having trouble grasping the components I need to develop and put together in order to have a solid, integrated security authentication mechanism for a custom C# .NET application that involves...
5
by: Cichy | last post by:
Hello, I'm writing a Client-Server application using sockets (asynchronous). There is a Server (Master) which accepts incoming connections, and Client (Slave). Afetr establishing connections...
5
by: kimtherkelsen | last post by:
Hi, I use the System.Data.OleDb.OleDbConnection class to establish a connection to a Oracle 10G database. The dsn connection string I use look like this: dsn=provider="MSDAORA.1";User...
7
by: TerpZebra | last post by:
I am having difficulty connecting to SQL Server 2000 on one of our servers via a VB6 program on Vista. I can connect fine to a different server, but it gives me the following error with the server...
5
by: myth0s | last post by:
Hello everybody :) I have trouble getting my ASP application to work. I googled a lot for a solution... many solutions I tried came from The Scripts, but none of them worked. Nonetheless, I think...
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: 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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
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,...

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.