<div dir="ltr"><div>Unless your network data happens to be character data using the encoding assumed by the functions in Network.Socket, bad things are going to happen.</div><div><br></div>Here is a quote from Network.Socket:<div>
<br></div><div>&quot;<span style="font-size:13px;color:rgb(0,0,0);font-family:sans-serif;line-height:18px">Do not use the </span><code style="font-size:13px;margin:0px;padding:0px;line-height:16px;color:rgb(0,0,0)">send</code><span style="font-size:13px;color:rgb(0,0,0);font-family:sans-serif;line-height:18px"> and </span><code style="font-size:13px;margin:0px;padding:0px;line-height:16px;color:rgb(0,0,0)">recv</code><span style="font-size:13px;color:rgb(0,0,0);font-family:sans-serif;line-height:18px"> functions defined in this module in new code, as they incorrectly represent binary data as a Unicode string. As a result, these functions are inefficient and may lead to bugs in the program.&quot;</span></div>
<div><span style="font-size:13px;color:rgb(0,0,0);font-family:sans-serif;line-height:18px"><br></span></div><div><span style="font-size:13px;color:rgb(0,0,0);font-family:sans-serif;line-height:18px">-Karl</span></div></div>
<div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, May 10, 2013 at 1:50 PM, Nathan Hüsken <span dir="ltr">&lt;<a href="mailto:nathan.huesken@posteo.de" target="_blank">nathan.huesken@posteo.de</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">It works when I am using Network.Socket.ByteString.<br>
I assume this is because the other recvFrom encodes the message with peekCStringLen, but I am not sure.<br>
<br>
Should the 2 implementations not behave the same besides returning a different datastructure for the received data??<div class="HOEnZb"><div class="h5"><br>
<br>
On 05/10/2013 06:34 PM, Nathan Hüsken wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hey,<br>
<br>
I am trying to write a small haskell application which forwards udp<br>
messages. The complete program is here: <a href="http://hpaste.org/87681" target="_blank">http://hpaste.org/87681</a><br>
<br>
Notice the lines:<br>
<br>
43  (msg,bytes,addr) &lt;- recvFrom sock 1024<br>
44  putStrLn $ &quot;Received: &quot; ++ show bytes ++ &quot; = &quot; ++ (show . length $ msg)<br>
<br>
If I understand correctly, bytes is the number of bytes in the message.<br>
This should be äquivalent to (length msg), correct?<br>
<br>
Now I send an udp message (by connecting over the forwarded port with<br>
enet), and get this output:<br>
<br>
Received: 52 = 41<br>
<br>
than I run it again, and get this output:<br>
<br>
Received: 52 = 43<br>
<br>
Why is the length of msg not equal  to 52?<br>
And why is it different from run to run?<br>
<br>
enet is unable to connect over this forward, by the way.<br>
<br>
Thanks!<br>
Nathan<br>
<br>
______________________________<u></u>_________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org" target="_blank">Beginners@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/<u></u>mailman/listinfo/beginners</a><br>
</blockquote>
<br>
<br>
______________________________<u></u>_________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org" target="_blank">Beginners@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/<u></u>mailman/listinfo/beginners</a><br>
</div></div></blockquote></div><br></div>