Non-blocking Connect for native ethernet client

Status
Not open for further replies.

dmhummel

Well-known member
I have a Teensy 4.1 device that needs to opportunistically connect to a socket server (Java Netty). I have approached this by simply triggering the connect function on a regular interval, but blocking for a few seconds every 30 seconds while trying a connection (to a non-existent server) is not ideal.

Is there a different way to create a connection with the Client concept that is non-blocking? I can easily poll a connection status if this was possible.
 
It can be done non-blocking, though there’s not a default way to do it, what it’s doing now is blocking while it’s polling and if it doesn’t connect in 10 seconds it gives up. Everything in FNET is non-blocking, but the NativeEthernet wrapper library is imitating the Ethernet library for the w5500 which is blocking, so in order for existing sketches to work with no changes it was made that way. That’s not to say I can’t add non-blocking methods I just haven’t had the time to work on it recently.
 
Ah thanks for the quick response. So its lacking from the Arduino "interface"? I'll look into how to implement with FNET. Unfortunately, I will also need to add different implementations for the wifi client I am using when this software runs on an ESP32.
 
It can easily be added to the client part if you don’t want to deal with learning a whole new API, looking at the client connect code you can easily see where the blocking takes place: https://github.com/vjmuzik/NativeEt...65e5d4584bf9/src/NativeEthernetClient.cpp#L77
Mostly everything in the while loop could be separated into it’s own polling function, likewise everything before the while loop would be in it’s own function to start the non-blocking process.
 
Status
Not open for further replies.
Back
Top