microsoft / devkit-sdk

Arduino library and package for the MXChip IoT DevKit
https://aka.ms/devkit
MIT License
68 stars 57 forks source link

WebServer available method blocks until a client connects #1023

Closed fmuntean closed 4 years ago

fmuntean commented 4 years ago

Trying the WiFiWebServer sample and in the loop method when calling WiFiClient client = server.available(); The thread is blocked here until the client connects to the server. This makes impossible to run anything else on the board.

Please make this method return null pointer when no client is connected to the server.

dooriya commented 4 years ago

@fmuntean Thanks for the feedback!

Currently, the underlining WiFiServer.available() is implemented as a BLOCKING operation in the Devkit SDK, which means the server would block until incoming client connection occurs.

Behind the scene, we leverage the TCPServer from mbed-os to implement the core function of the WifiServer class, which also use a blocking mode by default.

The improvement here can be providing the option to set_timeout or set_blocking for user. Then user can choose whether to use a blocking TCPServer or not according to his specific scenario.

JerryYangKai commented 4 years ago

Hi @fmuntean, We have released DevKit SDK 1.6.5 and added set_timeout option for server.available(). Please try it.