MCPcopy Create free account
hub / github.com/JoaoLopesF/RemoteDebug / asyncConnect

Method asyncConnect

src/utility/WebSocketsClient.cpp:723–761  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

721#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266_ASYNC)
722
723void WebSocketsClient::asyncConnect() {
724
725 DEBUG_WEBSOCKETS("[WS-Client] asyncConnect...\n");
726
727 AsyncClient * tcpclient = new AsyncClient();
728
729 if(!tcpclient) {
730 DEBUG_WEBSOCKETS("[WS-Client] creating AsyncClient class failed!\n");
731 return;
732 }
733
734 tcpclient->onDisconnect([](void *obj, AsyncClient* c) {
735 c->free();
736 delete c;
737 });
738
739 tcpclient->onConnect(std::bind([](WebSocketsClient * ws , AsyncClient * tcp) {
740 ws->_client.tcp = new AsyncTCPbuffer(tcp);
741 if(!ws->_client.tcp) {
742 DEBUG_WEBSOCKETS("[WS-Client] creating Network class failed!\n");
743 ws->connectFailedCb();
744 return;
745 }
746 ws->connectedCb();
747 }, this, std::placeholders::_2));
748
749 tcpclient->onError(std::bind([](WebSocketsClient * ws , AsyncClient * tcp) {
750 ws->connectFailedCb();
751
752 // reconnect
753 ws->asyncConnect();
754 }, this, std::placeholders::_2));
755
756 if(!tcpclient->connect(_host.c_str(), _port)) {
757 connectFailedCb();
758 delete tcpclient;
759 }
760
761}
762
763#endif

Callers 1

connectedCbMethod · 0.80

Calls 4

onDisconnectMethod · 0.80
onConnectMethod · 0.80
connectFailedCbMethod · 0.80
connectedCbMethod · 0.80

Tested by

no test coverage detected