×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Regular Contributor
    Join Date
    Jan 2008
    Posts
    272

    Question Bluetooth problem

    Dear friends,

    I am doing a bluetooth broadcaster application.

    My requirement is like this:

    My application should search the nearest devices, and send some files to those nearest devices.

    My application wont sit on those nearest devices.

    For that, I can able to get those remote device address, and can able to establish connection.

    And even I can able to send the file also.

    but the remote devices could not recieving my files.

    I dont know why it is not recieving.

    can you please tell me where I am doing wrong.

  2. #2
    Regular Contributor
    Join Date
    Jan 2008
    Posts
    272

    Re: Bluetooth problem

    Here I am providing the code:

    uuidSet = new UUID[1];
    uuidSet[0] = new UUID(0x0100); // l2cap


    public void servicesDiscovered(int transID, ServiceRecord[] servRecord) {
    for (int i = 0; i < servRecord.length; i++)
    {
    records.addElement(servRecord[i]);
    }
    }

    public void serviceSearchCompleted(int transID, int respCode)
    {

    // first, find the service search transaction index
    int index = -1;
    for (int i = 0; i < searchIDs.length; i++)
    {
    if (searchIDs[i] == transID)
    {
    index = i;
    break;
    }
    }


    // FIXME: process the error case

    synchronized (this)
    {
    notify();
    }
    }

    private boolean searchServices() {

    state = SERVICE_SEARCH;
    records.removeAllElements();
    searchIDs = new int[devices.size()];

    boolean isSearchStarted = false;

    for (int i = 0; i < devices.size(); i++)
    {
    RemoteDevice rd = (RemoteDevice)devices.elementAt(i);
    try {
    searchIDs[i] = discoveryAgent.searchServices(null, uuidSet, rd, this);
    }
    catch (Exception e)
    {
    e.printStackTrace();
    continue;
    }

    isSearchStarted = true;

    }

    if (!isSearchStarted) {
    return true;
    }

    try {
    wait(); // until services are found
    } catch (InterruptedException e) {
    return false;
    }

    // this "wake up" may be caused by 'destroy' call
    if (isClosed) {
    return false;
    }

    // actually, no services were found

    return true;
    }

  3. #3
    Regular Contributor
    Join Date
    Jan 2008
    Posts
    272

    Re: Bluetooth problem

    private boolean presentUserSearchResults()
    {
    for (int i = 0; i < records.size(); i++)
    {
    presentUserSearchResultsLocal(i);
    }
    return false;
    }

    private boolean presentUserSearchResultsLocal(int my_I)
    {
    int i = my_I;
    ServiceRecord sr = (ServiceRecord)records.elementAt(i);
    int a[] = sr.getAttributeIDs();
    String url = null;
    StreamConnection conn = null;
    //L2CAPConnection conn = null;
    try
    {

    url = sr.getConnectionURL(ServiceRecord.NOAUTHENTICATE_NOENCRYPT, false);
    conn = (StreamConnection)Connector.open(url,Connector.READ_WRITE);

    }
    catch (Exception e)
    {
    e.printStackTrace();
    return false;
    }
    byte[] imgData = getImageData("/duke.png");
    sendImageData(imgData, conn);
    try
    {
    conn.close();
    }
    catch (IOException e)
    {
    form.append("Exception while closing conn : " + e);
    }



    // close stream connection
    try
    {
    conn.close();
    }
    catch (IOException ee)
    {
    } // ignore
    }
    */
    }
    return true;
    }

  4. #4
    Regular Contributor
    Join Date
    Jan 2008
    Posts
    272

    Re: Bluetooth problem

    private byte[] getImageData(String imgName)
    {
    if (imgName == null)
    {
    return null;
    }

    InputStream in = getClass().getResourceAsStream(imgName);
    byte[] buff = new byte[1024];
    ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);

    try
    {
    while (true)
    {
    int length = in.read(buff);

    if (length == -1)
    {
    break;
    }

    baos.write(buff, 0, length);
    }
    }
    catch (IOException e)
    {
    return null;
    }

    return baos.toByteArray();
    }


    private void sendImageData(byte[] imgData, StreamConnection conn)
    {
    if (imgData == null)
    {
    return;
    }
    OutputStream out = null;
    try
    {

    out = conn.openOutputStream();


    out.write(imgData.length >> 8);
    out.write(imgData.length & 0xff);
    out.write(imgData);
    out.flush();
    }
    catch (IOException e)
    {
    System.err.println("Can't send image data: " + e);
    }

    // close output stream anyway
    if (out != null)
    {
    try
    {
    out.close();
    }
    catch (IOException e)
    {
    form.append("Exception while out.close() : " + e);
    } // ignore
    }

    }

  5. #5
    Regular Contributor
    Join Date
    Jan 2008
    Posts
    272

    Re: Bluetooth problem

    the above is my code.

    Please look into that once and suggest me.

    I dont know this approach is right or wrong.

    my application is working fine but the remote devices are not recieving any thing.

    my application wont sit on those remotedevices.

    another doubt is that with which connection I need to typecast while opening connection.

    Please help me.

Similar Threads

  1. Bluetooth Service Discovery Problem
    By rwan067 in forum Symbian Networking & Messaging (Closed)
    Replies: 0
    Last Post: 2007-03-18, 14:32
  2. Q: Problem with Nokia PC Suite and Bluetooth
    By Juha_74 in forum General Development Questions
    Replies: 0
    Last Post: 2007-03-13, 13:32
  3. Strange Problem with Bluetooth Connection
    By bigbadwolf in forum Symbian Networking & Messaging (Closed)
    Replies: 8
    Last Post: 2006-12-06, 09:51
  4. Bluetooth serviceDiscover problem Device Not Reachable
    By kashifqazi in forum Bluetooth Technology
    Replies: 1
    Last Post: 2006-10-13, 12:31
  5. Nokia SDK Bluetooth service re-discovery problem, Help Me!:(
    By tomsonxu in forum Bluetooth Technology
    Replies: 0
    Last Post: 2005-11-08, 07:51

Posting Permissions

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