title: Using bluecove to receive messages from phone
body: <p>I am trying to implement a server type specification on my pc that receives messages from my phone and then does stuff with them. I may have the entirely wrong end of the stick here, but I am using bluecove and have this on my pc:</p>
  
  <pre><code>public static void main(String[] args) throws IOException {
      System.out.println(System.getProperty("java.class.path"));
      //display local device address and name
      LocalDevice localDevice = LocalDevice.getLocalDevice();
      System.out.println("Address: "+localDevice.getBluetoothAddress());
      System.out.println("Name: "+localDevice.getFriendlyName());
      System.out.println("Discoverable: "+localDevice.getDiscoverable());
  
      DiscoveryAgent agent = localDevice.getDiscoveryAgent();
      RemoteDevice remoteDeviceArray[] = agent.retrieveDevices(0);
      System.out.println("array: " + Arrays.toString(remoteDeviceArray));
  
      SelectServiceHandler handler = new SelectServiceHandler(agent);
      for (int i=0; i&lt;remoteDeviceArray.length; i++)
      {
          RemoteDevice remoteDevice = (RemoteDevice)remoteDeviceArray[i];
          String address = remoteDevice.getBluetoothAddress();
          System.out.println("remoteAddress: " + address);
          if (address.equals(myAddress))
          {
              UUID[] uuidSet = new UUID[1];
              uuidSet[0] = new UUID(0x1105); //OBEX Object Push service
              int[] attrSet = new int[] {0x0100}; //Service name
              agent.searchServices(attrSet, uuidSet, remoteDevice, handler);
              System.out.println("successfully found phone");
              String service = agent.selectService(uuidSet[0], ServiceRecord.NOAUTHENTICATE_NOENCRYPT, false);
              Server server = new Server();
              server.startServer(service);
          }
      }
  }
  
  private void startServer(String service) throws IOException{  
      DataInputStream inputStream = Connector.openDataInputStream(service);
  }
  </code></pre>
  
  <p>The pc, on boot, looks through the devices it has already paired with. If one of them has "myAddress" (which I specified somewhere else - the id of my phone), it searches the phone's services, and tries to find the OBEX Object Push Service (which I have seen from various guides is what I want to be looking for here).
  I then try and open an input stream for this service, to receive messages. 
  Currently, I get the error:</p>
  
  <pre><code>Exception in thread "main" java.lang.ClassCastException: com.intel.bluetooth.obex.OBEXClientSessionImpl cannot be cast to javax.microedition.io.InputConnection
      at com.intel.bluetooth.MicroeditionConnector.openInputStream(MicroeditionConnector.java:565)
      at com.intel.bluetooth.MicroeditionConnector.openDataInputStream(MicroeditionConnector.java:545)
      at javax.microedition.io.Connector.openDataInputStream(Connector.java:127)
      at Server.startServer(Server.java:24)
      at Server.main(Server.java:80)
  </code></pre>
  
  <p>Which I understand from other posts might be because I am trying to cast a client service connection to a server inputstream, but I don't think that's what I am doing here.</p>
  
  <p>Any help would be greatly appreciated, I am really struggling with the whole concept of bluecove.</p>
  
  <p>Cheers.</p>