[Haskell-beginners] recvFrom return value different from length of resulting string

Karl Voelker ktvoelker at gmail.com
Sat May 11 20:43:15 CEST 2013


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.

Here is a quote from Network.Socket:

"Do not use the send and recv 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."

-Karl


On Fri, May 10, 2013 at 1:50 PM, Nathan Hüsken <nathan.huesken at posteo.de>wrote:

> It works when I am using Network.Socket.ByteString.
> I assume this is because the other recvFrom encodes the message with
> peekCStringLen, but I am not sure.
>
> Should the 2 implementations not behave the same besides returning a
> different datastructure for the received data??
>
>
> On 05/10/2013 06:34 PM, Nathan Hüsken wrote:
>
>> Hey,
>>
>> I am trying to write a small haskell application which forwards udp
>> messages. The complete program is here: http://hpaste.org/87681
>>
>> Notice the lines:
>>
>> 43  (msg,bytes,addr) <- recvFrom sock 1024
>> 44  putStrLn $ "Received: " ++ show bytes ++ " = " ++ (show . length $
>> msg)
>>
>> If I understand correctly, bytes is the number of bytes in the message.
>> This should be äquivalent to (length msg), correct?
>>
>> Now I send an udp message (by connecting over the forwarded port with
>> enet), and get this output:
>>
>> Received: 52 = 41
>>
>> than I run it again, and get this output:
>>
>> Received: 52 = 43
>>
>> Why is the length of msg not equal  to 52?
>> And why is it different from run to run?
>>
>> enet is unable to connect over this forward, by the way.
>>
>> Thanks!
>> Nathan
>>
>> ______________________________**_________________
>> Beginners mailing list
>> Beginners at haskell.org
>> http://www.haskell.org/**mailman/listinfo/beginners<http://www.haskell.org/mailman/listinfo/beginners>
>>
>
>
> ______________________________**_________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/**mailman/listinfo/beginners<http://www.haskell.org/mailman/listinfo/beginners>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20130511/cc3428d0/attachment.htm>


More information about the Beginners mailing list