Quantcast
Channel: Active questions tagged ubuntu - Stack Overflow
Viewing all articles
Browse latest Browse all 6186

Problem with Bluetooth running the server on Linux and the client on Windows using BlueZ and C++ : error 10051

$
0
0

I am running the server software on Linux Ubuntu with the following code:

  int serverSocket, clientSocket;  struct sockaddr_rc serverAddr = {0}, clientAddr={0};  socklen_t clientAddrSize = sizeof(sockaddr_rc);  // Create Bluetooth socket  serverSocket=socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);  if (serverSocket<0)  {    perror("socket creation failed: ");    return false;  }  bdaddr_t  bdaddr_any={{0,0,0,0,0,0}};// Bind the socket to any local Bluetooth adapter  serverAddr.rc_family = AF_BLUETOOTH;  serverAddr.rc_bdaddr = bdaddr_any; // bind to any local Bluetooth adapter  serverAddr.rc_channel = 20;  if (bind(serverSocket,(struct sockaddr*)&serverAddr,sizeof(serverAddr))<0)  {    perror("Bind failed");    close(serverSocket);    exit(EXIT_FAILURE);  }  // listen for incomming connections  if (listen(serverSocket,1) <0)  {    perror("Listen failed");    close(serverSocket);    exit(EXIT_FAILURE);  };  wxPrintf("Listening bluetooth\n");  while (true)  {    wxPrintf("Waiting for incoming Bluetooth connections...\n");    // Accept incoming connection    clientSocket = accept(serverSocket, (struct sockaddr*) &clientAddr,&clientAddrSize);    if (clientSocket<0)    {      perror("accept failed");      continue;    }

I am running the client software on Windows 10 with the following code:

    // Create a Bluetooth socket  m_serverSocket = socket(AF_BTH, SOCK_STREAM, BTHPROTO_RFCOMM);  SOCKADDR_BTH serverAddr = { 0 };  if (m_serverSocket == INVALID_SOCKET) {    IB_P_APP->IbLogOutputMessageAdd("Failed to create socket: error %d", WSAGetLastError());    return false;  }  // Set the address of the remote Bluetooth device to connect to  serverAddr.addressFamily = AF_BTH;  serverAddr.btAddr = *reinterpret_cast<BTH_ADDR*>(&m_Server.Address.ullLong); // this is the addres found by function BluetoothFindFirstDevice()  serverAddr.serviceClassId = RFCOMM_PROTOCOL_UUID;  serverAddr.port = 20; // Replace with the RFCOMM channel number to use  // Connect to the remote Bluetooth device  if (connect(m_serverSocket, reinterpret_cast<SOCKADDR*>(&serverAddr), sizeof(serverAddr)) == SOCKET_ERROR) {    IB_P_APP->IbLogOutputMessageAdd("Failed to connect to %s: error %d", m_bt_devices[index].szName, WSAGetLastError());    return false;  } type here

The server is listening on port 25 while the client tries to connect on the same port.The client first searches for the server, finds it and uses the server's address to connect.The connection on the client then fails with error code 10051 (or sometimes 10060)Running the same server software on a Windows 10 runs fine, client connecting to the server.

On Linux there is no firewall installed, using bluetoothclt I see it is registered and pairable.The bluetooth dongle is plugged into a USB port ands seen as USB2.0-BT.I have tried different ports without success.

Any help is highly appreciated!Best regards,Peter

I ported the server code to Windows and this worked fine, so both client and server running on a Windows platform.I reprogrammed it to ethernet communication and this also works fine.


Viewing all articles
Browse latest Browse all 6186

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>