locked
Bluetooth Socket connect() on WM5.0 RRS feed

  • Question

  • Hi

    I'm working on an application that receives a stream of data from a bluetooth device, and I connect to the device using bluetooth sockets.

    The program is supposed to function for days without user intervention once the initial setup is complete.  If no data is received for a certain timeout interval, I closesocket() then attempt to reconnect ie socket(), then connect().  This loops until a connection is restablished.

    The code works fine initially.  When the device moves out of range, connect() returns the WSAECONNREFUSED 10061 error.  When the device moves back in rage, connect() succeeds.

    Inevitably, however, the call to connect() suddenly returns WSAEINVAL.  When I get this error, the loop will closesocket() -> new socket() -> connect() again, but will keep encountering connect()'s WSAEINVAL error.  Once this happens, I'm stuck in the loop and can never re-establish the BT connection even when the device is within range. Note: the call to connect() is on a blocking socket.

    I cannot find any documentation regarding this type of error.  Has anyone ever experienced this on WM5.0?

    I can't post the code here, but the basic logic is like this:

    if (data receive timeout)
    {
    while(connect() fails)
    {
    closesocket();
    sleep(15seconds);
    create new socket();
    connect();
    }
    }

    Any help will be greatly appreciated.  Thanks!


    Friday, December 14, 2007 3:25 AM

Answers

  •  

    Hi Bitz...

     

    I believe that the socket is same and you are referring it to be a blocked socket coz once the connection was denied once over that socket.

     

    well there is an api setsockopt() which will help you set the socket options. please see if the properties of the socket has changed when the BT device moved out of the piconet.

     

    However i als have a question to you as I am developing PBAP profile using WINCE 5.0 evaluation copy. Is it actually possible to develope a profile in WINCE evaluation copy? If yes, is there a means by which we can get the connection ID for the obex applications?

    Monday, December 17, 2007 1:25 PM

All replies

  • Hi bitsmbytez,

     

    Note: the call to connect() is on a blocking socket.

    The socket is a new socket, how does it blocked?

     

    Best regards,

    Guang-Ming Bian - MSFT

    Monday, December 17, 2007 7:19 AM
  • Hi Guang-Ming

    Maybe I phrased that wrongly...  "The calls made to the socket are set to block", is probably more accurate.

    Does that help?

    Thanks
    bits
    Monday, December 17, 2007 9:08 AM
  •  

    Hi Bitz...

     

    I believe that the socket is same and you are referring it to be a blocked socket coz once the connection was denied once over that socket.

     

    well there is an api setsockopt() which will help you set the socket options. please see if the properties of the socket has changed when the BT device moved out of the piconet.

     

    However i als have a question to you as I am developing PBAP profile using WINCE 5.0 evaluation copy. Is it actually possible to develope a profile in WINCE evaluation copy? If yes, is there a means by which we can get the connection ID for the obex applications?

    Monday, December 17, 2007 1:25 PM
  • Hi,

    I've been reading the docs on Bluetooth sockets.  It says for connect() to return the WSAEINVAL error, it means:

    "Plug and Play, driver-stack event, or other error caused failure."

    What is a Plug and Play error, and what is a driver-stack event?

    Thanks,
    bits
    Tuesday, December 18, 2007 11:58 PM
  • Hi Bitz,

     

    Can you send me the code which you are executing to me. i need a little investigation to be done with reference to my code. i am facing a small problem in initialization prior to calling socket connect. u can send me on naval.patel@lntinfotech.com

     

    thanks.

     

    Wednesday, December 26, 2007 6:27 AM
  • i am calling connect of windows socket to connect to the remote Bluetooth device.  The return value i get is 10053.

    Can someone help me how to fix this error !!!

    /********* code snipet **********/
    SOCKADDR_BTH s;
    s.family = AF_BTH;
    s.btaddr = bt_addr;//remote BT device address
    s.serviceClassId = NULL_GUID;
    s.port = 0;

    connect(sock,(sockaddr *) name, sizeof(SOCKADDR_BTH));
    /********* code snipet **********/

    Thursday, December 27, 2007 12:03 PM
  • Change your code like this

    SOCKADDER_BTH s

    s.family =AF_BTH;

    s.btaddr = 0;        /*For listening sockets, it should generally be 0 to indicate that
                                  the use of any local Bluetooth adapter is fine. */

    s.port = BT_PORT_ANY;

    then bind the socket, then try to connect.

    Remember at the other side listen program should be running before connect executes...

    Friday, May 27, 2011 7:08 AM