zeromq / clrzmq4

ZeroMQ C# namespace (.NET and mono, Windows, Linux and MacOSX, x86 and amd64)
GNU Lesser General Public License v3.0
241 stars 112 forks source link

Important Update: ReceiveBytes returns now int, ReadString doesn't enc.GetMaxByteCount #22

Closed metadings closed 8 years ago

metadings commented 9 years ago

ZSocket.ReceiveBytes method now does return int, and -1 if there was a ZError. Do not use zmq_recv in favor of zmq_msg_recv! Please have a look on ZSocket.ReceiveFrame and ZSocket.ReceiveMessage, where you receive and send ZFrame msg and ZMessage msg (basically an IList<ZFrame>).

ZFrame.ReadString method now doesn't try = encoding.GetMaxByteCount(length).

ZFrame.ReadLine is a new method, which returns a string ending in LineFeed \n 0x0A possibly followed by a CarriageReturn \r 0x0D.

zanfranceschi commented 9 years ago

I'm not sure if it fits here -- i'm sorry if not. ZFrame.ReadString() is not reading all the received string in one call. I'm having to ZFrame.ReadString() more than once in a loop to read all the received string.

I'm doing something like:

string theStringIWant = string.Empty;
string auxString = string.Empty;

do
{
    auxString = frame.ReadString();
    theStringIWant += auxString;
}
while (!string.IsNullOrEmpty(auxString));

I've tried different Encoding and nothing changed. Anyway, I found out that for each special character used in the string, there is one less byte in the string after calling ReadString(). For instance:

If my sent string is: Hêllo

The following happens in the receiving side:

a = frame.ReadString();
b = frame.ReadString();
// a = Hêll
// b = o

That's way I'm using a loop.

Is this by design or is it a bug?

I'm using the nuget version 4.1.0.15

metadings commented 9 years ago

You definitifely need the update to the current version (v4.1.0.17)... I don't know if I got it right in the last version (v...15, v...16) so please just install/git pull the update.

That was a bug resolved in some commit with ReadString and ReadLine...

zanfranceschi commented 9 years ago

This bug persists in the 4.1.0.17 version. Just tried it.

metadings commented 9 years ago

I don't have problems right now... Please try writing/reading the string using Encoding.ASCII.

metadings commented 8 years ago

irrelevant, as of v4.1.0.xx