/** * called in arduino loop */ void WebSocketsClient::loop(void) { if(!clientIsConnected(&_client)) { #if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) if(_client.isSSL) { DEBUG_WEBSOCKETS("[WS-Client] connect wss...\n"); if(_client.ssl) { delete _client.ssl; _client.ssl = NULL; _client.tcp = NULL; } _client.ssl = new WiFiClientSecure(); _client.tcp = _client.ssl; } else { DEBUG_WEBSOCKETS("[WS-Client] connect ws...\n"); if(_client.tcp) { delete _client.tcp; _client.tcp = NULL; } _client.tcp = new WiFiClient(); } #else _client.tcp = new WEBSOCKETS_NETWORK_CLASS(); #endif if(!_client.tcp) { DEBUG_WEBSOCKETS("[WS-Client] creating Network class failed!"); return; } if(_client.tcp->connect(_host.c_str(), _port)) { connectedCb(); } else { connectFailedCb(); delay(10); //some little delay to not flood the server } } else { handleClientData(); } }
/** * called in arduino loop */ void WebSocketsServer::loop(void) { handleNewClients(); handleClientData(); }
void startBridge(void *subber, void *pubber) { int sendUDP = openSocket(INT_PORT1); int recvUDP = openSocket(INT_PORT2); int ret; int test; zmq_pollitem_t pool[4]; while(1) { /* 0=SUB, 1=PUB*/ pool[0].socket = subber; pool[0].events = ZMQ_POLLIN; pool[1].socket = pubber; if(peek(pubq) != NULL) { pool[1].events = ZMQ_POLLOUT; } else { pool[1].events = 0; } /* 2=OUT, 3=IN */ pool[2].socket = NULL; pool[2].fd = sendUDP; pool[2].events = 0; test = outDC != NULL || (subq != NULL && peek(subq) != NULL); test = test && waitACK == NULL; if(test) { pool[2].events |= ZMQ_POLLOUT; } if(waitACK != NULL) { pool[2].events |= ZMQ_POLLIN; } pool[3].socket = NULL; pool[3].fd = recvUDP; pool[3].events = ZMQ_POLLIN; if(outACK != NULL) { pool[3].events |= ZMQ_POLLOUT; } printf("Polling..."); ret = zmq_poll(pool, 4, -1); printf(" %d\n", ret); if(ret > 0) { if(pool[0].revents == ZMQ_POLLIN) { printf("handleSUB\n"); handleSUB(subber); } if(pool[1].revents == ZMQ_POLLOUT) { printf("handlePUB\n"); handlePUB(pubber); } if(((pool[2].revents) & (ZMQ_POLLOUT)) == ZMQ_POLLOUT) { printf("handleSData\n"); handleServerData(sendUDP); } if(((pool[2].revents) & (ZMQ_POLLIN)) == ZMQ_POLLIN) { printf("handleSAck\n"); handleServerACK(sendUDP); } if(((pool[3].revents) & (ZMQ_POLLIN)) == ZMQ_POLLIN) { printf("handleCData\n"); handleClientData(recvUDP); } if(((pool[3].revents) & (ZMQ_POLLOUT)) == ZMQ_POLLOUT) { printf("handleCAck\n"); handleClientACK(recvUDP); } } } }
/** * called in arduino loop */ void WebSocketsClient::loop(void) { if(!clientIsConnected(&_client)) { #if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) if(_client.isSSL) { DEBUG_WEBSOCKETS("[WS-Client] connect wss...\n"); if(_client.ssl) { delete _client.ssl; _client.ssl = NULL; _client.tcp = NULL; } _client.ssl = new WiFiClientSecure(); _client.tcp = _client.ssl; } else { DEBUG_WEBSOCKETS("[WS-Client] connect ws...\n"); if(_client.tcp) { delete _client.tcp; _client.tcp = NULL; } _client.tcp = new WiFiClient(); } #else _client.tcp = new WEBSOCKETS_NETWORK_CLASS(); #endif if(!_client.tcp) { DEBUG_WEBSOCKETS("[WS-Client] creating Network class failed!"); return; } if(_client.tcp->connect(_host.c_str(), _port)) { DEBUG_WEBSOCKETS("[WS-Client] connected to %s:%u.\n", _host.c_str(), _port); _client.status = WSC_HEADER; // set Timeout for readBytesUntil and readStringUntil _client.tcp->setTimeout(WEBSOCKETS_TCP_TIMEOUT); #if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) _client.tcp->setNoDelay(true); if(_client.isSSL && _fingerprint.length()) { if(!_client.ssl->verify(_fingerprint.c_str(), _host.c_str())) { DEBUG_WEBSOCKETS("[WS-Client] certificate mismatch\n"); WebSockets::clientDisconnect(&_client, 1000); return; } } #endif // send Header to Server sendHeader(&_client); } else { DEBUG_WEBSOCKETS("[WS-Client] connection to %s:%u Faild\n", _host.c_str(), _port); delay(10); //some litle delay to not flood the server } } else { handleClientData(); } }