Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
chan0722 opened this issue Sep 25, 2023 · 2 comments
Assignees

Comments

@chan0722
Copy link

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!

@MaxTMcCoy
Copy link

Same issue I'm also using 0.5.3

@syderbit
Copy link

you can try with

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants