0

WebSocket not able to send message when it connects. I am using ESP8266 board and arduinoWebSockets library.

Here is the code I have for websocket event:

void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t length) {

switch(type) {

    case WStype_CONNECTED:
        {
            IPAddress ip = webSocket.remoteIP(num);
            Serial.printf("[%u] Connected from %d.%d.%d.%d url: %s\n", num, ip[0], ip[1], ip[2], ip[3], payload);

            // send message to client
            webSocket.sendTXT(num, "Connected");
        }
        break;
    case WStype_TEXT:
        Serial.printf("[%u] get Text: %s\n", num, payload);
        break;

}

When ever a socket client is connected I want to send some initial details to it. But I am not receiving the Connected message. Socket is getting connected fine.

If I connect to the websocket, send some message then disconnect and reconnect it again means I am receiving the connected message.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.