×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Sep 2008
    Posts
    8

    client connection to Nokia phone

    I have developed an application that starts a server, then waits for a client to connect. The ServiceRecord shows (using getConnectionURL()) that the address for a client to connect to is 001a166725e2:26 - is there any way to set the server to listen on a different channel? Or does anyone have other advice? I am able to connect to the other device if I make a client connection from the phone, but for what I am doing, I must set up a server on the phone. The device that I am using as a client to connect (not j2me) is able to connect to the Nokia phone, but it is not linked to my application (wrong channel?). Is there something that I have to modify in the ServiceRecord? Any help would be greatly appreciated.

    Thank you.

    Sincerely,

    Beau

  2. #2
    Registered User
    Join Date
    Sep 2008
    Posts
    8

    Re: client connection to Nokia phone

    I am stuck! Please somebody reply!!

    Beau

  3. #3
    Registered User
    Join Date
    Sep 2008
    Posts
    8

    Client connects to device, but not connected to my application

    Below is the code from my application (The application offers SPP service, and then just hangs. The other device connects to the phone, but is not linked to my application)

    Thanks for your help (If you can help).

    Sincerely,

    Beau
    ----------------------------

    import java.io.*;

    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.io.*;
    import javax.bluetooth.*;

    /**
    * @author Beau
    */
    public class dsrcMIDlet
    extends MIDlet implements javax.microedition.lcdui.CommandListener
    {
    private Alert safetyAlert = null;
    private Command mExitCommand = new Command("Exit", Command.EXIT,1);

    StreamConnectionNotifier notifier = null;
    LocalDevice dsrcCellPhone = null;
    DataInputStream input;
    UUID myService = new UUID("1101",true);
    String myMIDlet = this.getClass().getName();
    String filter = "*";

    public void startApp() {
    initialize(); // Initialize the safetyAlert interface

    try {
    input = setupConnections(); // Connect the cell phone to the eb506 (create input stream from other device)
    } catch (BluetoothStateException ex) {
    ex.printStackTrace();
    } catch (ClassNotFoundException ex) {
    ex.printStackTrace();
    } catch (IOException ex) {
    ex.printStackTrace();
    }
    Display.getDisplay(this).setCurrent(safetyAlert); // display the Alert


    try {
    do {
    safetyAlert.setString(getMessage(input)); // get incoming message and put it into safetyAlert
    Display.getDisplay(this).setCurrent(safetyAlert); // display the Alert with the new message
    } while ((safetyAlert.getString()).length() > 1); // with only a carraige return, no more messages
    } catch (IOException ex) {
    ex.printStackTrace();
    }


    try {
    PushRegistry.registerConnection(new String("btspp://localhost:"
    + myService.toString()), myMIDlet, filter); // Register this connection in the PushRegistry for auto start-up
    } catch (ClassNotFoundException ex) {
    ex.printStackTrace();
    } catch (IOException ex) {
    ex.printStackTrace();
    }

    // This next section will set the Alert to display the registered PushRegistry connections
    String[] connectionList = PushRegistry.listConnections(false);
    int listcount = connectionList.length;
    StringBuffer connlist = new StringBuffer("Connections (# = "+listcount+"):");
    while(listcount > 0){
    connlist.ensureCapacity(connlist.length()+30);
    connlist.append(connectionList[listcount-1]);
    listcount--;
    }
    safetyAlert.setString(new String(connlist));
    Display.getDisplay(this).setCurrent(safetyAlert); // display the Alert

    }

    private void initialize() {

    safetyAlert = new Alert("Incoming DSRC message: ", "Please Wait...",null,null);
    safetyAlert.setTimeout(Alert.FOREVER);
    safetyAlert.addCommand(mExitCommand);
    safetyAlert.setCommandListener(this);
    return;
    }

    public DataInputStream setupConnections() throws BluetoothStateException, IOException, ClassNotFoundException {

    dsrcCellPhone = LocalDevice.getLocalDevice();

    dsrcCellPhone.setDiscoverable(DiscoveryAgent.GIAC);
    notifier = (StreamConnectionNotifier)Connector.open("btspp://localhost:" + myService.toString());

    safetyAlert.setString("waiting for connection");
    Display.getDisplay(this).setCurrent(safetyAlert); // display the Alert

    /* This next line is where the application stalls, waiting for a client
    * to connect. I connect with my other device and it is able to connect
    * to the phone, but is not linked to this application */
    StreamConnection sconn = notifier.acceptAndOpen();

    /* If I connect with this section of code instead, (connect from phone
    * directly to my other device), there is no problem with transmitting
    * data (But the application does not auto-start when the incoming SPP
    * connection occurs.
    DiscoveryAgent dsrcAgent = dsrcCellPhone.getDiscoveryAgent();
    String connString = dsrcAgent.selectService(myService, ServiceRecord.NOAUTHENTICATE_NOENCRYPT, false);
    StreamConnection sconn = (StreamConnection)Connector.open(connString);
    input = sconn.openDataInputStream();*/


    safetyAlert.setString("client device connected");
    Display.getDisplay(this).setCurrent(safetyAlert); // display the Alert
    return sconn.openDataInputStream();
    }


    /* This method gets an ASCII message from the input stream and converts it
    * to a UniCode string and returns the Unicode string */
    public String getMessage(DataInputStream d) throws IOException {

    StringBuffer strBuff = new StringBuffer();
    char store = 0;
    int count = 0;

    while (count < 32) { // maximum message length is 32 characters
    count++;
    store = (char) d.readByte(); // read the next byte of the stream and store as a char
    if (store == 0x000D)
    break;
    strBuff.append(store);
    }
    return strBuff.toString();
    }


    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
    }

    public void commandAction(javax.microedition.lcdui.Command command, javax.microedition.lcdui.Displayable displayable) {
    if (displayable == safetyAlert) {
    if (command == mExitCommand) {
    Display.getDisplay(this).setCurrent(null);
    destroyApp(true);
    notifyDestroyed();
    }
    }
    }
    }

Similar Threads

  1. Nokia N-Series Complete Model Line-Up
    By Dopod in forum General Development Questions
    Replies: 6
    Last Post: 2008-07-22, 20:16
  2. Http connection problem in 6310i
    By teahola in forum Mobile Java General
    Replies: 1
    Last Post: 2002-10-03, 18:46

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •