<div dir="ltr"><div>I am trying to send multicast messages from one thread, and receive them on another. The sending thread reads lines from a file and sends them. However, the receiving thread does not receive all the messages - it seems to miss the last 10 message or so. If I run other programs to listen for the multicast message, they receive them fine. So I think the issue is something to do with receiving, not sending. I keep the program alive with a threadDelay, so it shouldn't be halting prematurely. If I add a small delay after each send, it works fine. And if I make the input file smaller, it works fine.</div><div><br></div><div>On the provided data file, on my system (64-bit Ubuntu, GHC 7.8.2), the receiver fails to receive lines 125-140. Compiled with no optimizations.</div><div><br></div><div>Thanks for any help!</div><div><br></div><div>The relevant code snippets are below, and the sample data file and full program are attached.</div><div><br></div><div>    -- Loop to receive all the packets</div><div>    let receiveMulticast = do</div><div>            (msg, _) <- recvFrom recvSock 32628</div><div>            putStrLn . BS.unpack $ BS.take 100 msg</div><div>            receiveMulticast</div><div>    _ <- forkIO receiveMulticast</div><div><br></div><div>    -- Send every line from a file as multicast message</div><div>    inputFile <- openFile "data" ReadMode</div><div>    fileLines <- BS.lines <$> BS.hGetContents inputFile</div><div>    let sendMulticast msg = do</div><div>            sendTo sendSock msg addr</div><div>            -- Receiver FAILS to receive last few messages unless this </div><div>            -- thread delay exists... why?!</div><div>            -- threadDelay (1) </div><div>    mapM_ sendMulticast fileLines</div><div>    hClose inputFile</div><div><br></div><div>    threadDelay (1000*1000*1000) -- Delay for 1000 seconds</div></div>