Websockets Non-Blocking MOD5234

Discussion to talk about software related topics only.
Post Reply
Quickdeploy
Posts: 5
Joined: Fri Sep 03, 2021 10:12 pm

Websockets Non-Blocking MOD5234

Post by Quickdeploy »

We have an application that has several task, we seem to have a problem where the application stops and waits for a Websockets connection?
The application needs to continue even if a web browser is not connected. Our code is similar to the LED example code. We are just sending messages out the websockets. We are not doing anything with the RV message.

Should I post some code or does any one have an idea what we need to do?
User avatar
pbreed
Posts: 1088
Joined: Thu Apr 24, 2008 3:58 pm

Re: Websockets Non-Blocking MOD5234

Post by pbreed »

Create a new task that just manages the websocket stuff .....

Are you creating a websocket to an external server?

Or is an external device creating a websocket via our server?

Give me an outline of what tasks you have created and what the desired data flow looks like and whats presently blocking... I can make better suggestions.
Quickdeploy
Posts: 5
Joined: Fri Sep 03, 2021 10:12 pm

Re: Websockets Non-Blocking MOD5234

Post by Quickdeploy »

Thank you for the response;

We got it basically working but let me describe as maybe you have better design.

We have main within main we open two separate serial ports to communicate to 2 separate serial devices. There where no assigned task for this. Then we have a file that allow TCP connections from a 3rd external device this is assigned as a task. Then we have Websockets that was then also assigned as a task. So in simple operation the three device exchange info but there is also the abilty for an end user to access a web page dashboard with control and display. The issue is that the main loops need to stay running even without a websocket connection.

What was happening is main was waiting for semaphore forever until web sockets connection from a webbrowser was started. Our simple solution was to re-order things and make main higher priority than web sockets.

It is working now, but if you have a suggestion let us know?

We also have another issue that I will post separate but in short how to we reclaim the orphaned websockets.
User avatar
pbreed
Posts: 1088
Joined: Thu Apr 24, 2008 3:58 pm

Re: Websockets Non-Blocking MOD5234

Post by pbreed »

The way I would do this is keep a list of file descriptors I care about...
IE Serial ports, tcp connections, websockets...

and put them all in a select.
That way the task wakes up for the desired activity on any of the differing fd's
The fd returned form the open serial, or websockets can be used just like the fd returned from a tcp socket in select.

See the example:
2.X NNDK: nburn\examples\StandardStack\tcp\tcpmultisocket
3.X NNDK: nburn\examples\TCP\TcpMultiSocketServer
Post Reply