×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    3

    Bluetooth game runs in emulator, not on phone

    I have created a bluetooth game that works on the toolkit emulator fine but will not work on real phones, could someone please show me where I'm going wrong? The following code handles all the bluetooth implementation within the game. Thanks!

    Code:
    public void run() {
       
       Thread thisThread = Thread.currentThread();
       if ( serverThread == thisThread ){
       
       try {
          LocalDevice local = LocalDevice.getLocalDevice();
          if (!local.setDiscoverable(DiscoveryAgent.GIAC)) {
             serverCanvas.append("Failed to change to the " + "discoverable mode", null);
             return;
          }
    
       StreamConnectionNotifier notifier = (StreamConnectionNotifier)Connector.open("btspp://localhost:" + "86b4d249fb8844d6a756ec265dd1f6a3");
       
       StreamConnection conn = notifier.acceptAndOpen();
    
       InputStream in = conn.openInputStream();
       
       // Receive data here
       conkin[0] = (byte)in.read();
       conkin[1] = (byte)in.read();
       conkin[2] = (byte)in.read();
       conkin[3] = (byte)in.read();
       serverCanvas.append("1 = " + conkin[0] + ",2 = " + conkin[1] + ",3 = " + conkin[2] + ",4 = " + conkin[3] , null);
    
       in.close();
       conn.close();
       notifier.close();
       } catch (BluetoothStateException e){
       serverCanvas.append("bluetoothStateException: ", null);
       serverCanvas.append(e.getMessage(), null);
       } catch (IOException e) {
       serverCanvas.append("IOException: ", null);
       serverCanvas.append(e.getMessage(), null);
       }
          }
       
       // *****************************************************
       else if (clientThread == thisThread ){
             
       try{
          LocalDevice local = LocalDevice.getLocalDevice();
          DiscoveryAgent agent = local.getDiscoveryAgent();
       
          String connString = agent.selectService(new UUID("86b4d249fb8844d6a756ec265dd1f6a3", false),
          ServiceRecord.NOAUTHENTICATE_NOENCRYPT, false);
       
          if(connString != null) {
          try {
          StreamConnection conn = (StreamConnection)
          Connector.open(connString);
       
          // Send data Here
          OutputStream out = conn.openOutputStream();
       
          conkout[0] = 5;
          conkout[1] = 16;
          conkout[2] = 7;
          conkout[3] = 18;
       
          //   byte test = (byte)getPowerUp();
          out.write(conkout[0]);
          out.write(conkout[1]);
          out.write(conkout[2]);
          out.write(conkout[3]);
       
          out.close();
          conn.close();
       
          clientCanvas.append("message sent correctly", null);
          
       } catch (IOException e) {
       clientCanvas.append("IOException: ", null);
       clientCanvas.append(e.getMessage(), null);
       }
       } else {
       clientCanvas.append("unable to locate service", null);
       }
       } catch (BluetoothStateException e) {
       clientCanvas.append("BluetoothStateException: ", null);
       clientCanvas.append(e.getMessage(), null);
       }
          
       }
    }

  2. #2
    Nokia Developer Champion
    Join Date
    Mar 2005
    Location
    Paris
    Posts
    814

    Re: Bluetooth game runs in emulator, not on phone

    what kind of problem do you get ?

  3. #3
    Registered User
    Join Date
    Nov 2005
    Posts
    3

    Re: Bluetooth game runs in emulator, not on phone

    The client can't find the server

  4. #4
    Nokia Developer Expert
    Join Date
    Jun 2005
    Posts
    923

    Re: Bluetooth game runs in emulator, not on phone

    Is the real device Bluetooth turned on?

    You could also try first discovering the device than searchServices() on a selected device.

    Daniel

  5. #5
    Registered User
    Join Date
    Nov 2005
    Posts
    3

    Re: Bluetooth game runs in emulator, not on phone

    yup, the bluetooth device is turned on.

    I think it may be an issue with searching for services rather than just specifing one. if anyone can give me a simple working example that would be fantastic. All I am looking to do is send and recieve several variables to determine the outcome of a game.

Similar Threads

  1. Handling Game being Interrupted by Phone calls
    By Woody_FX in forum Mobile Java General
    Replies: 6
    Last Post: 2006-12-21, 06:43
  2. Reading phone book using Bluetooth
    By woogack in forum Bluetooth Technology
    Replies: 0
    Last Post: 2004-07-30, 03:58
  3. Transfer Application or Game From Phone to PC..
    By guideball in forum PC Suite API and PC Connectivity SDK
    Replies: 1
    Last Post: 2003-05-08, 00:06
  4. Phone Lock-Up Using Bluetooth (requires battery pull!!)
    By cyberabi in forum Bluetooth Technology
    Replies: 1
    Last Post: 2003-05-05, 18:40
  5. 6210 bluetooth battery not recognised by phone
    By pablake in forum Bluetooth Technology
    Replies: 1
    Last Post: 1970-01-01, 02:00

Posting Permissions

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