ArduinoWebsockets icon indicating copy to clipboard operation
ArduinoWebsockets copied to clipboard

[ 5236][E][WiFiClient.cpp:313] setSocketOption(): fail on -1, errno: 9, "Bad file number"

Open chan0722 opened this issue 2 years ago • 3 comments

Describe the bug I'm not sure why this error occurs, because I can connect to my websocket in postman, but there is no way to connect to my websocket in esp32.

To Reproduce Steps to reproduce the behavior. This should include:

  • The library version you are using -> gilmaimon/ArduinoWebsockets@^0.5.3
  • The board you are using ->ESP32 DEVKITV1
  • Information about other components in the system (do you use third party client/server software?) -> websocket runs in render

Expected behavior Hope the author can help

Code #include <Arduino.h> #include <ArduinoWebsockets.h> #include <WiFi.h>

const char* ssid = "Xiaomi12T"; //Enter SSID const char* password = "1234567890"; //Enter Password const char* websockets_server_host = "ws://fipt.onrender.com"; //Enter server adress const uint16_t websockets_server_port = 3000; // Enter server port

using namespace websockets;

WebsocketsClient client; void setup() { Serial.begin(115200); // Connect to wifi WiFi.begin(ssid, password);

// Wait some time to connect to wifi
for(int i = 0; i < 10 && WiFi.status() != WL_CONNECTED; i++) {
    Serial.print(".");
    delay(1000);
}

// Check if connected to wifi
if(WiFi.status() != WL_CONNECTED) {
    Serial.println("No Wifi!");
    return;
}

Serial.println("Connected to Wifi, Connecting to server.");
// try to connect to Websockets server
bool connected = client.connect(websockets_server_host, websockets_server_port, "/");
if(connected) {
    Serial.println("Connected!");
    client.send("Hello Server");
} else {
    Serial.println("Not Connected!");
}

// run callback when messages are received
client.onMessage([&](WebsocketsMessage message){
    Serial.print("Got Message: ");
    Serial.println(message.data());
});

}

void loop() { // let the websockets client check for incoming messages if(client.available()) { client.poll(); } delay(500); }

Additional context This is the output I got: ..Connected to Wifi, Connecting to server. [ 5207][E][WiFiClient.cpp:313] setSocketOption(): fail on -1, errno: 9, "Bad file number" Not Connected!

chan0722 avatar Sep 25 '23 17:09 chan0722

Same issue I'm also using 0.5.3

MaxTMcCoy avatar Oct 13 '23 20:10 MaxTMcCoy

you can try with

const char* websockets_connection = "ws://fipt.onrender.com"; client.connect(websockets_connection );

syderbit avatar Feb 18 '24 00:02 syderbit