Callbacks for sockets

Hi there, is there a way to have callbacks for sockets? At least for connection and receive events?

Thanks in advance
Alex

hi @Alex1
Currently, Sockets doesn’t support callbacks.
As a workaround, I think you can try doing it with threads.
as having a thread for the sockets receiving data and another thread for the application.

Thanks Karim, I was trying that approach. What seems awkward tome is having to try and catch exceptions.
Normally you will have your server sitting quietly until a request comes, however even with threads if you just sit and wait the watchdog will reboot the mcu which causes everything to start over.
Maybe it’s just my experience while trying out the web server (the same example in the docs running on a premium VM over an ESP32DevKitC)
I finally got it working by placing a watch dog for 25 secs and a socket.settimeout(10000), however then your code will get dirty with try/except, kicking the watchdog, etc. Not exactly what I had in mind when trying the example.

Would be great if we move towards the callback route some day and steer clear of any watchdog interference. IMHO it’s the direction most languages are moving now days.

Thanks
Alex

I’ll make sure to pass your suggestion to the dev team.
Thanks :smile: