I want to create a UDP listener that is non-blocking.
To do so I use SysSockSelect function. The problem is that the value diReady (Number of sockets that are ready for IO) never becomes 1.
The code I have is:
Hi, sorry for budding in.
Have you tried to program the blocking sockets in a different program with a different task yet?
If you build your communication in a different task, your main program does not get hindered by blocking communication.
Another way is to implement communication via asynchronous jobs with a callback.
Try searching the CODESYS library repo for the job manager (cannot recall what its name is), maybe it can help you out.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I want to create a UDP listener that is non-blocking.
To do so I use SysSockSelect function. The problem is that the value diReady (Number of sockets that are ready for IO) never becomes 1.
The code I have is:
tvTimeout.tv_sec:= 0;
tvTimeout.tv_usec:= 0;
fdRead.fd_count:= 1;
fdRead.fd_array[0]:= hListenSocket;
Socket_Result := NBS.SysSockSelect(NBS.SOCKET_FD_SETSIZE, ADR(fdRead), 0, 0, ADR(tvTimeout), ADR(diReady));
I am sure data is ready for IO because when I call the function SysSockRecv data is read.
The same code I use in CoDeSys v2.3 and there it works.
Does anyone know why this doesn't work in v3.5 SP10?
Thanks,
Richard
Hi Richard,
I would recommend to use this project from that forum post based on netbase services:
l viewtopic.php?f=21&t=6625&hilit=UDP+raspberry#p13743 l
BR
Edwin
Hi Edwin,
Function block UDP_Receive is also blocking.
But I have used UDP_Receive in a separate task so now it doesn't matter that is it blocking.
Thanks,
Richard
Hi, sorry for budding in.
Have you tried to program the blocking sockets in a different program with a different task yet?
If you build your communication in a different task, your main program does not get hindered by blocking communication.
Another way is to implement communication via asynchronous jobs with a callback.
Try searching the CODESYS library repo for the job manager (cannot recall what its name is), maybe it can help you out.