Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7429457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:58:24+00:00 2026-05-29T08:58:24+00:00

I have a receive thread listening with the BluetoothServerSocket accept() call. This thread will

  • 0

I have a receive thread listening with the BluetoothServerSocket accept() call. This thread will be killed and restarted by another thread pretty frequently. When it gets the kill signal, it closes the BluetoothServerSocket therefore causing an IOException in accept(), and gets out of the infinite-loop. But occasionally, during these starts and restarts the listenUsingRfcommWithServiceRecord() call will catch a “bad file number” IOException and exit the loop prematurely. I think I may not be shutting down the BT component correctly in kill(?) but haven’t figure out anything yet… Could someone give me some pointers?

private class ReceiveThread extends Thread {
    private final static String TAG = "ReceiveThread";
    private BluetoothServerSocket mmBtServer;
    private BluetoothSocket mmBtSocket;

    public ReceiveThread() {
        setName(TAG);
    }

    public void run() {
        if(D) Log.d(TAG,"RceiveThread running");

        while(true) {
            try {
                SetState(SERVICE_STATE.LISTENING);
                mmBtServer = mBtAdapter.listenUsingRfcommWithServiceRecord(mAppName, mUUID);

                if(D) Log.d(TAG,"ReceiveThd accepting connection");
                mmBtSocket = mmBtServer.accept();
                // Close server once socket establishes
                mmBtServer.close();

                if(D) Log.d(TAG, "Connection Established");
                SetState(SERVICE_STATE.CONNECTED_BUSY);



                /** Handle Processing **/



                // Close socket
                mmBtSocket.close();
            } catch (IOException e) {
                SetState(SERVICE_STATE.NOT_CONNECTED);
                Log.d(TAG,"IOException in ReceiveThread", e);
                break;
            }

            SetState(SERVICE_STATE.CONNECTED_IDLE);
        }
    }

    public void kill() {
        try {
            if(mmBtSocket!=null) mmBtSocket.close();
            if(mmBtServer!=null) mmBtServer.close();
        } catch (IOException e) {
            Log.d(TAG,"Failure killing ReceiveThread", e);
        }
        SetState(SERVICE_STATE.NOT_CONNECTED);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T08:58:24+00:00Added an answer on May 29, 2026 at 8:58 am

    If anyone’s interested.. I’ve found that this happens only on certain phones. I can consistently reproduce this on my Samsung Galaxy S after about 20-30 cycles of stops and starts. Quite frequently, I will also catch a “out of memory” from bluez which leads me to the problem resides beneath the api… I cannot reproduce this on Droid X, HTC G2, or myTouch 4G.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a method that will receive a string , but before I can
In Socket Programming, how will a Unix thread receive a Socket CLOSE event from
I have a background thread listening to network, using a callback to process and
I have a worker thread that is listening to a TCP socket for incoming
I have a thread that is listening on a socket and forwarding on the
My form receives asynchronous callbacks from another object on random worker threads. I have
In my Workflow Foundation 4.0 RC app I have a 'Receive' and 'SendReplyToReceive' WCF
I have been unable to receive UDP multicast under VxWorks 5.5. I've joined the
I receive a list of image URLs and currently I have several hidden img
I have an array of bytes that I receive from an external entity. It

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.