Author Topic: [C++][CwclClient] Retry mechanism  (Read 8600 times)

wuchihchung

  • Guest
[C++][CwclClient] Retry mechanism
« on: May 14, 2015, 03:12:48 PM »
Hi Mike, good day :

 I'm making a PC tool which can connect to a BT ear phone accessory, and the connection is a SPP connection.
 In some causes, not sure the root cause, tool fails to connect to accessory and the error code is 43. I tried to reconnect few times w/ a 2000ms sleep, but still got error 43 after each retry.

      m_Client.Connect();
      Sleep(2000);
      m_Client.Connect();
      Sleep(2000);
      m_Client.Connect();
      Sleep(2000);
      ...
 

 The accessory engineer told me that I should close the socket before retry. So :

1. Before I call CwclClient::Connect() again, should I close socket?  How(in WCL lib, while programming, the BT socket is almost transparent to me) ?
2. What's the general suggestion from you when we encounter error 43 (how can we retry, how can we dig out the root cause instantly...) ?
   

Thanks a lot.
 

Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3675
  • Karma: 1000
    • Wireless Communication Libraries
Re: [C++][CwclClient] Retry mechanism
« Reply #1 on: May 14, 2015, 03:18:49 PM »
Hi,

You should use OnConnect event, analize result and restart re-connect from event handler by starting timer (in your case). Sockets are available for BT only in *nix and MS.

wuchihchung

  • Guest
Re: [C++][CwclClient] Retry mechanism
« Reply #2 on: May 14, 2015, 04:11:58 PM »
Oh Mike, yes, the error 43 did came from onConnect() event, and then I will signal back to main thread to trigger another Connect().

And can't get your point, what I mean is should I close the socket before reconnect ?
[I'm now working on Windows 8.1]

For example :
   m_Client.Connect();
   OnConnect() -> error 43;
   Sleep(2000);
   m_Client.ReleasePreviousSocket();  // <-- is there sth. like that ? Or sokcet is well handled by WCL, I don't need to worry about it
   m_Client.Connect();
   ...

Thanks a lot.

Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3675
  • Karma: 1000
    • Wireless Communication Libraries
Re: [C++][CwclClient] Retry mechanism
« Reply #3 on: May 14, 2015, 04:17:14 PM »
There is no sockets in WCL (at least sockets visible outside WCL). So no, you should not. But it is not so good idea to call Connect from OnConnect event. It is possible but better if you use something like timer or Post message and then reconnect.

On Win 8 also take a look that there is no native BT dialog opened. Win 8 has lot of conflicts between Metro UI and standard UI when it works with hardware. Metro UI may block native code from accessing to HW functions (such as Bluetooth and WiFi).

wuchihchung

  • Guest
Re: [C++][CwclClient] Retry mechanism
« Reply #4 on: May 14, 2015, 04:25:35 PM »
There is no sockets in WCL (at least sockets visible outside WCL). So no, you should not.
-> OK, got it.

But it is not so good idea to call Connect from OnConnect event. It is possible but better if you use something like timer or Post message and then reconnect.
-> Yup, I post a message back to main thread msgqueue and then trigger Connect() agagin.
     I remember long time ago I called Connect() in OnConnect(), it seemed not work always.

On Win 8 also take a look that there is no native BT dialog opened. Win 8 has lot of conflicts between Metro UI and standard UI when it works with hardware. Metro UI may block native code from accessing to HW functions (such as Bluetooth and WiFi).
-> OK, noted. So many pain points on Win8


Thanks :) ~

Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3675
  • Karma: 1000
    • Wireless Communication Libraries
Re: [C++][CwclClient] Retry mechanism
« Reply #5 on: May 14, 2015, 04:28:56 PM »
You are welcome.

>>OK, noted. So many pain points on Win8

Fortunately they fixed it in Win 01 (at least on Win 10 Preview I tested all works much better).

 

Sitemap 1 2 3 4 5 6 7