I am still learning the basics of Haskell and am currently working on porting some Java code to Haskell. My current problem is UDP recvFrom using Network.Socket.ByteString.
The problem is this method :
public abstract SocketAddress receive(ByteBuffer dst) throws IOException Receives a datagram via this channel. If a datagram is immediately available, or if this channel is in blocking mode and one eventually becomes available, then the datagram is copied into the given byte buffer and its source address is returned. If this channel is in non-blocking mode and a datagram is not immediately available then this method immediately returns null.
The fact is that when I use Network.Socket.ByteString.recvFrom , my code blocks are waiting for the packet to appear at this moment. It does not return something like Maybe to indicate whether something was received or not (similarly in Java there is null when data was not available)
I found this topic: https://mail.haskell.org/pipermail/haskell-cafe/2010-August/082725.html
At the end of this there are several ways: 1) FFI 2) run recvFrom in its own thread
I'm not sure that I can use any of these approaches at the moment (not enough knowledge). I want to get something similar to the Java non-blocking method of receiving: to get the necessary information if it is available, or just nothing if there is no single UDP packet. Anyone can indicate what will be the best approach, any code snippets, has someone already dealt with this problem?
source share