netconn_close whilst blocked in netconn_recv
Posted: Sat Jan 12, 2019 11:37 pm
I have WiFi in APSTA mode and the webserver will serve http on port 80 on both networks. I have a websocket server using netconn api (for efficiency compared to sockets) on another port.
Once the websocket it opened, it blocks on netconn_recv waiting for data.
If I want to change between AP and STA to serve the webpage, all is fine, but unless the websocket is closed in one network (by closing the browser tab which sends the proper request to close the websocket), it won't open on the other. I'd like the network most recently served a webpage to own the websocket, so I want to be able to shut it down from the server side.
I can detect the event I want to trigger the netconn_close with a structure pointer to the connection, but it doesn't seem to have the same effect as closing the web browser tab that has opened the websocket.
So is there a "nice" way to unblock a netconn_recv by closing or deleting its connection from the server side when the client hasn't been closed?
It might be a good opportunity to redo the webserver and websocket code so they are both on port 80 and use non blocking sockets, but I wondered if there was a simple tweak to do it with netconn.
Once the websocket it opened, it blocks on netconn_recv waiting for data.
If I want to change between AP and STA to serve the webpage, all is fine, but unless the websocket is closed in one network (by closing the browser tab which sends the proper request to close the websocket), it won't open on the other. I'd like the network most recently served a webpage to own the websocket, so I want to be able to shut it down from the server side.
I can detect the event I want to trigger the netconn_close with a structure pointer to the connection, but it doesn't seem to have the same effect as closing the web browser tab that has opened the websocket.
So is there a "nice" way to unblock a netconn_recv by closing or deleting its connection from the server side when the client hasn't been closed?
It might be a good opportunity to redo the webserver and websocket code so they are both on port 80 and use non blocking sockets, but I wondered if there was a simple tweak to do it with netconn.