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

  • Home
  • SEARCH
  • 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 706321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:09:10+00:00 2026-05-14T04:09:10+00:00

i am creating a bluetooth based server program in Bluez which basically handles connections

  • 0

i am creating a bluetooth based server program in Bluez which basically handles connections from multiple devices. I have constructed two threads; one to scan the remote devices and another to connect with the devices that are broadcasting the service. Again, a separate thread is extracted from a thread pool for each of the newly connected devices which will then communicate with the server over a RFCOMM channel.

After establishing connection with a remote device, the server will send commands to the remote bluetooth device. Once the remote device a reply, the server reads that reply and stores it.

Now, the problem is whenever I get a reply back from the device the program crashes stating a “segmentation fault”. Can anyone tell me a possible cause for this. The part of the code that does this is given here.

void startCommunication( int newSocket )
{


    char buf[MODZ_MAX_DATA_SIZE] = "\0";
        char previousData[ MODZ_MAX_DATA_SIZE ] = "\0"; 
        time_t recvTime, prevRecvTime;
        char dataToBeSent[ 4*MODZ_MAX_DATA_SIZE ] = "\0";
        char *result;

if( sendDataToClient( newSocket, CMD_SEND) == EXT_ERROR )   //send acknowledgement first
    printf("Couldn;t send ack\n");
else { printf("Date send woot! woot! %s\n", CMD_SEND); } 

memset( buf, '0', sizeof(buf) );

while( 1 ){
recvTime = time( ( time_t * )0 );

    if( readDataFromClient( newSocket, buf ) == EXT_ERROR ){
        printf( "Read Error\n" );
        break;
    }
    printf( "Data received = %s\n", buf );

    strcpy( previousData, buf );

    // store the data in a file and send to web

    // check if the web has any data to send and if there is then send
    result = "here we update the challenge";
    strcpy( dataToBeSent, result );
    free( result );
    result = NULL;

    //strcpy( buf, "We will soon update the database" );
    if( sendDataToClient( newSocket, dataToBeSent ) == EXT_ERROR ){
        break;
    }

    }           
close( newSocket );

if( result != NULL ){
    free( result );

}

printf( "\n****************Device disconnected***************\n" );

}

  • 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-14T04:09:11+00:00Added an answer on May 14, 2026 at 4:09 am

    One obvious problem:

    result = "here we update the challenge";
    strcpy( dataToBeSent, result );
    free( result );
    

    You are freeing a pointer that was not allocated with malloc. That could well cause a segmentation fault.

    In the future, try to use gdb to figure out exactly where your program crashes.

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

Sidebar

Related Questions

I am creating a program which can send test or data to Bluetooth devices.
I have an Android Bluetooth application which manages a couple of remote devices( Capsules
I am creating a program used to connect to a embedded bluetooth device with
I'm creating Bluetooth custom application, but I have a small issue. When in my
i am creating an application which connects 4 devices. one of them acts as
I'm currently creating an iPhone app (Xcode 4.3.1, IOS 5) that could use Bluetooth
Creating a server-side socket will fail if I'm trying to use the same port
Creating a JApplet I have 2 Text Fields, a button and a Text Area.
I'm creating a simple WP7 app, to have all network settings in one place,
I am trying to create a Service for my application which will negotiate Bluetooth

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.