async client working

This commit is contained in:
Markus Sattler
2016-01-29 13:16:02 +01:00
parent 1275914c86
commit 76853c7a73
2 changed files with 14 additions and 7 deletions

View File

@ -54,8 +54,8 @@
// select Network type based
#ifdef ESP8266
//#define WEBSOCKETS_NETWORK_TYPE NETWORK_ESP8266
#define WEBSOCKETS_NETWORK_TYPE NETWORK_ESP8266_ASYNC
#define WEBSOCKETS_NETWORK_TYPE NETWORK_ESP8266
//#define WEBSOCKETS_NETWORK_TYPE NETWORK_ESP8266_ASYNC
#else
#define WEBSOCKETS_NETWORK_TYPE NETWORK_W5100
#endif

View File

@ -67,8 +67,9 @@ void WebSocketsClient::begin(const char *host, uint16_t port, const char * url)
// todo find better seed
randomSeed(millis());
#endif
#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266_ASYNC)
asyncConnect();
#endif
}
void WebSocketsClient::begin(String host, uint16_t port, String url) {
@ -504,7 +505,7 @@ void WebSocketsClient::connectedCb() {
client->tcp = NULL;
// reconnect
// c->asyncConnect();
c->asyncConnect();
return true;
}, this, std::placeholders::_1, &_client));
@ -543,18 +544,24 @@ void WebSocketsClient::connectFailedCb() {
void WebSocketsClient::asyncConnect() {
DEBUG_WEBSOCKETS("[WS-Client] asyncConnect...\n");
AsyncClient * tcpclient = new AsyncClient();
if(!tcpclient) {
DEBUG_WEBSOCKETS("[WS-Client] creating AsyncClient class failed!");
DEBUG_WEBSOCKETS("[WS-Client] creating AsyncClient class failed!\n");
return;
}
tcpclient->onDisconnect([](void *obj, AsyncClient* c) {
c->free();
delete c;
});
tcpclient->onConnect(std::bind([](WebSocketsClient * ws , AsyncClient * tcp) {
ws->_client.tcp = new AsyncTCPbuffer(tcp);
if(!ws->_client.tcp) {
DEBUG_WEBSOCKETS("[WS-Client] creating Network class failed!");
DEBUG_WEBSOCKETS("[WS-Client] creating Network class failed!\n");
ws->connectFailedCb();
return;
}