473,774 Members | 2,218 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

1 New Member
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 setupConnection s() 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 2417

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

Similar topics

0
1425
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 updates a database and notifies all Web clients on the LAN that the button has been pressed. This is the simpliest form of the system which I would then develop into a complete application. I plan on developing the Web GUI as an ActiveX Document and...
0
1322
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 string and then either puts it in to html or txt format which is saved on the website I know this is a client and server application its just getting it set up on a Cgi-bin im confused with,
4
13312
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 Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\temp.MDF;User ID=MyUsername;password=MyPass;DATABASE=Test;Integrated Security=False;User Instance=True"); conn.Open();
3
3744
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 References\localhost\References.vb' In this file a line of code reports the following error: Line of code: Dim results() As Object = Me.Invoke("GetCustomers", New Object() {Country})
0
1043
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 a client application connecting to a remote Windows (server) application that is not running IIS or SQL Server. I want the users to be able to seemlessly start the application on the client, use the same credentials they used to log on to their...
5
2780
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 with all Slaves I wanna hit a button "Automatic", then everything must be reorganised, there is an ellection for a new Master. Everything is all right when I'm connecting manually (when I hit a button connect), but after hitting this button...
5
8410
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 ID=test;Data Source="172.30.0.25/ JBOS";Password=test; This works fine in Windows XP and Windows server 2003 but I have a customer that try to connect to the database from a Windows 2000
7
6565
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 in question: "Unable to connect to database. Please check your internet connection Error# -2147467259 SQL Server does not exist or access denied"
5
21657
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 somebody out there can help me ;) So, I have an ASP.NET 2.0 application on the test server. That application doesn't work, I get "Server Application Unavailable" all the time but... while experimenting with all the possibles solutions I found over...
0
9621
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
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10267
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
10106
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
10046
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
8939
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5358
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...
0
5484
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3611
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.