timum-viw / socket.io-client

A socket.io-client implementation for ESP8266 and Arduino
228 stars 90 forks source link

It should work but it doesn't. #26

Closed Tvde1 closed 3 years ago

Tvde1 commented 6 years ago

The Serial monitor no longer outputs "disconnected". I think it connects but idk why it won't work.

My server:

const server = http.createServer((request, response) => {  
    response.writeHeader(200, {'Content-Type': 'text/html'});  
    response.write(html);
    response.end(); 
});
server.listen(80);
const io = socketio.listen(server);

io.on('connection', socket => {
    console.log('New client.'); //This DOES log.
    socket.on('sample', sample => {
        console.log('Received: ' + sample);
    });
});

And my client

typedef struct Config {
    String host = "192.168.2.5";
    int port = 80;
};

Config config;
SocketIoClient socket;

void setup() {
    //I am connected to wifi
    socket.begin(config.host.c_str(), config.port);
    socket.on("connect", event);
    socket.on("disconnect", [](const char* a, size_t b){});

}

void loop() {
    socket.loop();
    delay(1000);
    socket.emit("sample", "\"100\"");
}

I can't find why this won't work.

timum-viw commented 6 years ago

Could you elaborate what exactly does not work? Is it throwing errors or does it simply not log the event? What output does the console give you?

Tvde1 commented 6 years ago

It doesn't output anything

Tvde1 commented 6 years ago

It used to output something like

[SioC] disconnect
1 event not found

So I guess it is connected but it doesn't connect.

Also event is just

void event(const char * a, byte_t b) {
    Serial.println("Connected to Socket.io server.");
}
timum-viw commented 6 years ago

so you see the client connect at your server, but the console for the esp remains empty?

Tvde1 commented 6 years ago

Yes, exactly that

Tvde1 commented 6 years ago

Is this lib outdated?

Bhupesh-V commented 5 years ago

Yes, exactly that

Any solutions I 'm facing the same problems