How exactly does Haskell's Network.UDP `accept` work?

82 Views Asked by At

In Network.UDP, accept :: ListenSock -> ClientSockAddr -> IO UDPSock

I understand how to call this function and I've read the source code for it. However, when I try to use it, it causes my code to hang at the accept and never advance.

Is the client supposed to do something after the fact to complete the acceptance? Assume we've created a client UDP socket, which is of type UDPSocket. Assume we've created a server UDP socket, which is of type ListenSocket. If the client, in another thread, sends bytes to the server, then should this complete? Because my code never completes; it just sits there seemingly waiting for an acceptance to complete.

let (incomingData, clientSockAddr) = recvFrom serverSocket
accept serverSocket clientSockAddr

I know that UDP is a connectionlist protocol, so running accept to have the server send data to the client is not strictly necessary (because sendTo :: ListenSocket -> Bytes -> ClientSockAddr -> IO () exists), but the accept function exists in this module, so I want to understand it.

0

There are 0 best solutions below