Coder Social home page Coder Social logo

clrzmq4's People

Contributors

bluca avatar c-rack avatar cezarypiatekgc avatar hawkans avatar metadings avatar sm2vsd avatar sphaero avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

clrzmq4's Issues

Cannot find a way to build dependency dlls (libsodium and libzmq) into ZeroMQ.dll manifest

I need to deploy libzmq.dll and libsodium.dll as part of ZeroMQ.dll's manifest. There's code in the Platform.Win32.cs source file that extracts these dependencies to AppData's temporary folder. However, I need to know if there is already a mechanism that is used to create a manifest for ZeroMQ.dll that would contain these dlls as part of the manifest. Right now, in code, I do not see any such thing.

In summary, my goal is to be able to deploy the ZeroMQ.dll, with manifest that contains the unmanaged dependencies which can be extracted at runtime. Do you have some ready made configuration that I could use?

@metadings Can you please help me here?

Thanks!

System.AccessViolationException with Majordomo sample

Hi,
I'am new to ZeroMQ and I'd like to evaluate the Majordomo pattern in C#. I have downloaded the samples and run the MDBroker, MDWorker (x4) and one MDClient2 (async mode).

In a run of 100000 calls, I randomly experience this error (on a worker side or the broker side) :

Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. at System.Buffer.Memmove(Byte* dest, Byte* src, UInt32 len) at System.String.CtorCharPtrStartLength(Char* ptr, Int32 startIndex, Int32 length) at ZeroMQ.ZFrame.ReadStringNative(Int32 byteCount, Encoding encoding) at ZeroMQ.ZFrame.ReadString(Int32 length, Encoding encoding) at ZeroMQ.ZFrame.ToString(Encoding encoding) at ZeroMQ.ZFrame.ToString() at Examples.Program.Main(String[] args) dans C:\SVN\Majordomo\Broker\Program.cs:ligne 554

I Compiled the Majordomo sample with Visual Studio 2015 under .NET 4.6 (Windows 8.1 Enterprise).

I have the the issue on an EC2 VM under Windows Server 2012 (I thought my problem was linked to my computer).

If I run the Broker in JAVA (with Jeromq lib) and keeping client and workers in c# (clrzmq4) I have no problem anymore.

Thank you for your help.

Problem with polling

What I'm trying to accomplish is to implement reading a message from one of two sockets, wherever it arrives first. As far as I understand polling (zmq_poll) is the right thing to do (as demonstrated in mspoller in guide). Here I'll provide small pseudo-code snippet:

TimeSpan timeout = TimeSpan.FromMilliseconds(50);

using (var receiver1 = new ZSocket(ZContext.Current, ZSocketType.DEALER))
using (var receiver2 = new ZSocket(ZContext.Current, ZSocketType.PAIR))
{
    receiver1.Bind("tcp://someaddress");
    // Note that PAIR socket is inproc:
    receiver2.Connect("inproc://otheraddress");

    var poll = ZPollItem.CreateReceiver();

    ZError error;
    ZMessage msg;

    while (true)
    {
        if (receiver1.PollIn(poll, out msg, out error, timeout))
        {
            // ...
        }

        if (receiver2.PollIn(poll, out msg, out error, timeout))
        {
            // ...
        }
    }
}

As you can see it is actually the same exact implementation as in mspoller in guide.

In my case receiver2 (PAIR socket) should receive a large number of messages. In fact I've created a test in which number of messages sent to it is always greater than the number of messages it is capable to receive (at least in demonstrated implementation).

I've run the test for 2 seconds, and I was very surprised with results:

  • Number of messages sent to receiver2: 180 (by "sent" I mean that they are handed out to another PAIR socket not shown in the previous snippet);
  • Number of messages received by receiver2: 21 ??? Only 21 messages in 2 seconds??? 10 messages per second???

Then I've tried to play with different timeout values and I've found out that it significantly influences the number of messages received. Duration (2 seconds) and number of messages sent (180) remain the same. The results are:

  • timeout value of 200 milliseconds - number of messages received drops to 10 (5 per second);
  • timeout value of 10 milliseconds - number of messages received rises to 120 (60 per second).

The results are telling me that polling simply does not work. If polling were working properly, as far as I understand the mechanism, timeout should not have any influence in this scenario. No matter if we set timeout to 1 hour or 5 milliseconds - since there are always messages to receive there's nothing to wait for, so the loop should work with the same speed.

My another big concern is the fact that even with very small timeout value receiver2 is not capable to receive all 180 messages. I'm struggling here to accomplish receiving rate of 100 messages per second, although I've selected ZeroMQ which should be very fast (benchmarks are mentioning numbers as 6 million messages per second).

So my question is obvious: am I doing something wrong here? Is there a better way to implement polling?

Thanks

Is ZeroMQ.dll version decreased?

I had a project which installed ZeroMQ 4.1.0.17 by nuget on 2016-01-15, in the .csproj file these new lines were added:

    <Reference Include="ZeroMQ, Version=4.1.0.42169, Culture=neutral, PublicKeyToken=4a9630883fd6c563, processorArchitecture=MSIL">
      <SpecificVersion>False</SpecificVersion>
      <HintPath>..\..\packages\ZeroMQ.4.1.0.17\lib\net40\ZeroMQ.dll</HintPath>
    </Reference>

I created a new project today and install ZeroMQ 4.1.0.19 by nuget. When I use this new project to communicate with the old project, I got and exception when calling ZFrame.ReadString:

Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt

Then I dive into this bug and find that in the new project the ZeroMQ.dll has a smaller version number:

    <Reference Include="ZeroMQ, Version=4.1.0.20957, Culture=neutral, PublicKeyToken=4a9630883fd6c563, processorArchitecture=MSIL">
      <HintPath>..\..\packages\ZeroMQ.4.1.0.19\lib\net40\ZeroMQ.dll</HintPath>
      <Private>True</Private>
    </Reference>

So there is a number reversal: package 4.1.0.17 has a DLL 4.1.0.42169 and package 4.1.0.19 has a DLL 4.1.0.20957
In the new project, I referenced to the ZeroMQ.dll 4.1.0.42169 in 4.1.0.17 manually, and the exception is gone.
Seems there is something wrong with the ZeroMQ.dll in 4.1.0.19?

.NET Core Compatibility

You're probably aware that .NET Core becomes very important target these days, and that it is the future when it comes to portability. Do you have any plans to support it? +1 for this.

Thanks!

When subscribed for all, subscriber receives empty messages

I have problem with PUB/SUB communication. When I set socket.SubscribeAll() the subscriber receives empty frames. Although publisher sends single-frame message, containing X bytes, subscriber receives singe empty frame message. If publisher sends multi-frames message, each frame non-empty, subscriber receives multi-frame message, but all frames are empty.

If I set socket.Subscribe("123"), subscriber behaves normally (it will receive "123xxxx..." messages).

What I'm doing wrong?

Thanks!

SendFrame method in ZSocket disposes of ZFrame even if error = EAGAIN

the code does frame.Dismiss in the finally clause, which does not seem right to me.
from my tests it does seem the message is stable when EAGAIN is returned and i can resend the message.
though the documentation in zmq is not completely clear, it does stand to reason that the message will be dismissed and nullified when the method succeeds and not on EAGAIN.
thoughts?

Not compatible with Universal Windows application.

Unable to download on Universal Windows Platform App. On attempting to install the nuget, I get

Error Package restore failed. Rolling back package changes for 'uwp1-'. 0
ZeroMQ 4.1.0.21 is not compatible with UAP,Version=v10.0. Some packages are not compatible with UAP,Version=v10.0. ZeroMQ 4.1.0.21 is not compatible with UAP,Version=v10.0 (win10-arm). Some packages are not compatible with UAP,Version=v10.0 (win10-arm). ZeroMQ 4.1.0.21 is not compatible with UAP,Version=v10.0 (win10-arm-aot). Some packages are not compatible with UAP,Version=v10.0 (win10-arm-aot). ZeroMQ 4.1.0.21 is not compatible with UAP,Version=v10.0 (win10-x64). Some packages are not compatible with UAP,Version=v10.0 (win10-x64). ZeroMQ 4.1.0.21 is not compatible with UAP,Version=v10.0 (win10-x64-aot). Some packages are not compatible with UAP,Version=v10.0 (win10-x64-aot). ZeroMQ 4.1.0.21 is not compatible with UAP,Version=v10.0 (win10-x86). Some packages are not compatible with UAP,Version=v10.0 (win10-x86). ZeroMQ 4.1.0.21 is not compatible with UAP,Version=v10.0 (win10-x86-aot). Some packages are not compatible with UAP,Version=v10.0 (win10-x86-aot).

Cannot load .dll file on .NET/Windows

Look: I do have OLD binaries in the i386 and amd64 folders.

So I need new libzmq.dll and libsodium.dll, compiled on MSVC2010, MSVC2013 and MSVC2015.

Mapping of ZContextOption wrong

The definition of the ZContextOption enum is different from the values in libzmq.

#define ZMQ_IO_THREADS  1
#define ZMQ_MAX_SOCKETS 2
public enum ZContextOption
{
    IO_THREADS,
    MAX_SOCKETS,
    IPV6
}

To reproduce use following code (where as 1024 is the default value for max sockets):

System.Diagnostics.Debug.Assert(zcontext.MaxSockets == 1024);

Hello Issues! Code Comments required

Hello Issues! I'm going to make the first issue :)

There are code comments required (the ones which you see in IntelliSense). Example:

/// <summary>
/// Create a socket with the current context and the specified socket type.
/// </summary>
/// <param name="socketType">A <see cref="ZSocketType"/> value for the socket.</param>
/// <returns>A <see cref="ZSocket"/> instance with the current context and the specified socket type.</returns>
public static ZSocket Create(ZContext context, ZSocketType socketType, out ZError error)

Anyone here to help? - Uli

something wrong with PrefixStyle.None

example code:

    var url = "tcp://*:5555";
    var style = PrefixStyle.None;

    //make response msg
    var responseMsg = new ResponseMessage()
    {
        code = ErrorCode.OK,
        type = MsgType.LOGIN,
        responseStr = "this is local server!"
    };
    var serverStream = new MemoryStream();
    ProtoBuf.Serializer.SerializeWithLengthPrefix(serverStream, responseMsg, style);

    // start server.
    var server = Task.Factory.StartNew(() => ZmqTools.WaitRequestFromClient(url, serverStream.GetBuffer()));

    //make request msg
    var clientMsg = new UserMessage() {login = new LoginMessage() {account = "xxx",password = "xxxxxx"}, type = MsgType.LOGIN};
    var clientStream = new MemoryStream();
    ProtoBuf.Serializer.Serialize(clientStream, clientMsg);

    var reply = ZmqTools.WaitReplyFormServer("tcp://127.0.0.1:5555", clientStream.GetBuffer());
    //Console.WriteLine($"client reply {reply}");

    var response = ProtoBuf.Serializer.DeserializeWithLengthPrefix<ResponseMessage>(reply,style);
    Console.WriteLine($"client response {response?.responseStr ?? "failed"}");

server.Wait(ZmqTools.TimeOut);

result:

    client response failed

if i print the reply with code

    Console.WriteLine($"client reply {reply}");

results:

    client reply ��������this is local server!  
    client response failed  

if i change the style like this:

    var style = PrefixStyle.Base128;
    ......
    //Console.WriteLine($"client reply {reply}");

results is ok.

    client response this is local server!

but if the server is writtern by c++ running on a linux
everything goes the first case. i cannot Deserialize the msg correctlly.
something wrong to judge the head of a stream.

Unhandled Exception of type 'System.TypeInitializationException' occured in ZeroMQ.dll

capture

So I tried running the HWClient sample using the latest ZeroMQ nuget package. I've tried compiling it for both .net 4.0 and .net 4.5, and the results are the same.

Upon the instantiation of ZContext, TypeInitializationException gets thrown.

The inner exception is: {"UnmanagedLibrary[libzmq] Unable to load library "libzmq" from
"C:\TEMP\libzmq.dll". Inspect Trace output for details.":"C:\TEMP
\libzmq.dll"}

Misleading polling example ("Bug" in documentation) - attempt 2

I have to try to reopen #74 since it is closed based on WRONG conclusions. (You can see more details at #73)

@metadings has closed the original issue although he hasn't actually understand the issue at all.

Again, I can confirm that I've tested everything multiple times, and that I'm already using the corrected approach in my production (dealing with dozens of thousands messages per second) without any problem. If you don't believe - simply do the testing your own. I've already provided the code.

Cannot load .so file on Mono/ubuntu, Linux Mint

Hi

When I use the nuget package on linux I get the following exception. For some reason it is looking in /tmp for the .so file. If i copy the file there it all works perfectly. If I copy it to the same directory as the application it doesnt work. Any ideas how to get it to look at the local directory, I looked at the code and it seems like it should look in the BaseDir first.

Thanks

Dean

System.TypeInitializationException: An exception was thrown by the type initializer for ZeroMQ.lib.zmq ---> System.IO.FileNotFoundException: UnmanagedLibrary[libzmq] Unable to load library "libzmq" from "/tmp/libzmq.so". Inspect Trace output for details.
File name: '/tmp/libzmq.so' ---> System.DllNotFoundException: libzmq.so: cannot open shared object file: No such file or directory
at ZeroMQ.lib.Platform+Posix.LoadUnmanagedLibrary (System.String libraryName) [0x00000] in :0
at ZeroMQ.lib.zmq..cctor () [0x00000] in :0
--- End of inner exception stack trace ---
at ZeroMQ.ZContext..ctor () [0x00000] in :0
at ZeroMQ.ZContext.Create () [0x00000] in :0
at rsb.RSB.Main () [0x00000] in :0

Zmq Unknown error (110) from router socket

I use a router socket with router.RouterMandatory = RouterMandatory.Report

According to http://api.zeromq.org/4-0:zmq-setsockopt#toc24 the router should return EHOSTUNREACH when a message can not be routed but i get Unknown error (110) when i close the connected dealer socket.

try
{
   this.router.SendMore(new ZFrame(client.Id));
   this.router.Send(new ZFrame(rawMessage));
}
catch (ZException ex)
{
   System.Diagnostics.Debug.Assert(ex.ErrNo == ZError.EHOSTUNREACH);
}

Improving StreamDealer, ZSocket.Send and Receive Methods

Now to have a running StreamDealer to tcp://192.168.1.1:8080 ...

I want you to pull the updates or download a new release, if you're interested... I've made some changes to ZSocket.Receive, ZSocket.ReceiveFrame, ZSocket.ReceiveFrames and ZSocket.ReceiveMessage, and also to ZSocket.Send, ZSocket.SendFrame, ZSocket.SendFrameMore, ZSocket.SendFrames.

ToZ85Encoded adds zero termination to C# string

I implement ZAP for curve. When I encode the received client key, the ToZ85Encoded method adds an zero termination to the string. The follwing example reproduces the issue:

     var data = Encoding.ASCII.GetBytes("ABCD");
     var encoded = data.ToZ85Encoded();
     Debug.Assert("ABCD" == Encoding.ASCII.GetString(encoded));

I don't think this behavior is expected, but correct me when i'm wrong.
Workarround is easy, just add .TrimEnd('\0') to the client key.

Static Constructor and Static Variable for Context

Hi,

Just wondering why u are not using a Static Constructor and Static Variable for the Context.
It could be as easy as:

    static ZContext _context; // static = accessable for any instance

    // static constructor = called before first instanciation only
    static ZSocket()
    {
     _context = new ZContext();
    }

    public ZSocket(ZSocketType socketType)
    {
        _socketType = socketType;

        ZError error;
        if (!Initialize(out error))
        {
            throw new ZException(error);
        }
    }

And no one would have to care about the context anymore. You don't have to passe it to other Thread, as it just is there.
Or are there any reasons to instantiate 2 Contexts ?
Just my 2 cents.

Push Memory Leak using frames, probably apply to other schemes also

Using Frames
while(true)
{
_socket.Send(new ZFrame(data));
_socket.Send(new ZFrame(data));
...x10
Thread.SpinWait(200);
}

vs

while(true)
{
_socket.SendBytes(data,0,data.Length);
_socket.SendBytes(data,0,data.Length);
...x10
Thread.SpinWait(200);
}

When stressing the socket to test max throughput causes memory to leak.
C# GC is bad at disposing objects created in one thread / then sent via zeromq but not disposed, instead left to be disposed by GC by going out of scope.

Changing the spinwait on the send to a thread.Sleep allows GC to collect that memory avoiding a memory leak,

while(true)
{
_socket.Send(new ZFrame(data));
_socket.Send(new ZFrame(data));
...x10
Thread.Sleep(100);
}

A fix may be in the C# lib to explicitly call _frame.Dispose() _message.Dispose() once the socket was done using the message.

Why can't I use SetOption() to CURVE_SECRETKEY when using CurveZMQ?

I want to use CurveZMQ to for secure authentication and confidentiality for communications between a client and a server. But I cannot find any example in C#. I try to follow the API document step by step. And I encounter the problem in Setting CURVE_PUBLICKEY, CURVE_SECRETKEY and CURVE_SERVERKEY.

Here is my code.
The socket 'server.CurveSecretKey' threw an exception of type 'ZeroMQ.ZException':
at ZeroMQ.ZSocket.GetOption(ZSocketOption option, IntPtr optionValue, Int32& optionLength)\r\n at ZeroMQ.ZSocket.GetOption(ZSocketOption option, Byte[]& value)\r\n at ZeroMQ.ZSocket.get_CurveSecretKey()"

public static byte[] StringToByteArray(string hex)
        {
            return Enumerable.Range(0, hex.Length)
                             .Where(x => x % 2 == 0)
                             .Select(x => Convert.ToByte(hex.Substring(x, 2), 16))
                             .ToArray();
        }

var context = new ZContext();
server = new ZSocket(context, ZSocketType.ROUTER);
server.SetOption(ZSocketOption.CURVE_SERVER, 1);
string curveSKey = "8E0BDD697628B91D8F245587EE95C5B04D48963F79259877B49CD9063AEAD3B7";
var skey = StringToByteArray(curveSKey);
server.SetOption(ZSocketOption.CURVE_SECRETKEY, skey);

EAGAIN Exception Rasied not sure it should be

Hi,

I copied the Example of the PollIn method but the ZError doesn't seem to be populated it throws a real exception instead.

serverSocket is a Rep socket.

The output of the Exception is
EAGAIN(11): Resource temporarily unavailable

Any ideas what I did wrong. I would have expected it to not throw an exception but to have filled the error variable populated.

Thanks

Dean

public void MainServerLoop()
{
log.Debug ("Starting The server Loop");
var poll = ZPollItem.CreateReceiver();
ZMessage value;
ZError error;
while (true) {
log.Debug ("Waiting for Message");
try{
if (serverSocket.PollIn (poll, out value, out error, TimeSpan.FromMilliseconds (64))) {
log.Debug ("Message There");
ZMessage response = ProcessMessage (value);
serverSocket.SendMessage (response);
} else {
if (error == ZError.ETERM)
log.Debug ("ETERM Error");
//return; // Interrupted
if (error != ZError.EAGAIN)
log.Debug ("EAGAIN Error");
throw new ZException (error);
log.Debug ("No Message Found");
}
} catch (Exception e){
log.Debug ("There was an Exception");
log.Debug (e);
}
}
log.Debug ("Exited the MainSeverLoop");
}

Send/Receive Buffer Size always 0 and HWM issue

I have a binded PUB socket in one task and a connected SUB socket in a separate task in the same ZContext / process - using the inproc protocol - they are talking fine, and if I sleep the SUB task I can see the PUB task sending regardless, and then the SUB task catches up. When the PUB task is obviously buffering while the SUB task is a asleep (I am sending a queue of 100000 messages in a loop) - the pubSocket.SendBufferSize remains at zero - and the subSocket.ReceiveBufferSize remains at zero which does not seem right.

Furthermore - setting the HWM (before Binding or Connecting) is having no effect - if I set PUB HWM to 100 for instance, and publish 10000 messages in 10 seconds (sleep for 1ms between sends), and sleep the SUB task this whole time - I still receive ALL the messages when the SUB socket resumes receiving - even though both send and receive buffer size remain at zero - ie No messages are being dropped. Ultimately I think this is what is causing grief in the application problem I am trying to solve.

There are no HWM examples or examples using ReceiveBufferSize/SendBufferSize - so can someone please throw me a bone and confirm that this very recent release does not have issues in this area and / or provide me with an example.

This is my first involvement with zmq and github in general so let me know if I am going about getting answers / assistance the wrong way.

unicode string decoded error

when reading a unicode string from recieved message, some data is lost. this piece code will show the problem:

private static void Main(string[] args)
{
    var push = new ZSocket(ZContext.Current, ZSocketType.PUSH);
    push.Bind("tcp://127.0.0.1:12345");
    var pull = new ZSocket(ZContext.Current, ZSocketType.PULL);
    pull.Connect("tcp://127.0.0.1:12345");

    var str = "中文字符串";
    Console.WriteLine("str send: {0}", str);
    using (var msg = new ZMessage(new[] {new ZFrame(str),}))
        push.SendMessage(msg);
    using (var msg = pull.ReceiveMessage())
        Console.WriteLine("str recv: {0}", msg[0].ReadString());
}

output:
str send: 中文字符串
str recv: 中?

Breaking: ReceiveMessage moving ref ZMessage

I'm moving the method parameter, so the new method looks like

    public bool ReceiveMessage(ref ZMessage message, ZSocketFlags flags, out ZError error)

I'm also removing namespace Devices, so the RouterDealerDevice is now directly in the ZeroMQ namespace.

Communicating with C++ ZMQ

I'm using 4.1.4 in my C++ app. This is a sample code:

char tempStr[] = "ABCD";
zmq_msg_t zmsg;
zmq_msg_init_size(&zmsg, 4);
memcpy(zmq_msg_data(&zmsg), tempStr, 4);
int rc = zmq_send(reqSocket, &zmsg, sizeof(zmsg), 0);
zmq_msg_close(&zmsg);

This will send 64 byte frame with actual ABCD from offset 16.

In C# I have:

ZFrame request = responder.ReceiveFrame();
byte[] reqBytes = new byte[100];
int n = request.Read(reqBytes, 0, 100);

reqBytes contains this 64 bytes and of course the actual data is located from offset 16. Question - how can I properly extract/construct data which is compatible with C++ zmq_msg_t at C# side? Hard coding offset looks very ugly.

receiveframe times out with EGAIN exactly the 255th time

Hi,

I don't know if this is an issue with my usage or a real issue that needs fixing. Either way, please see if you can help

I am using zmq router-dealer configuration. The server is written in python and runs on linux. My dealer client is written in c# with clrzmq4 and runs on a windows machine. It sends messages and waits from the response

    public Boolean sendMessage(Dictionary<String, String> msgDict)
    {
        ZError err;
        String errStr;
        var reqFrame = new ZFrame(JsonConvert.SerializeObject(msgDict));
        retval = socket.Send(reqFrame, out err);
        if (err != null)
        {
            errStr = String.Format("Error while sending command {3} {0} {1}", err.Text, err.Number, err.Name);
            return false;
        }

        err = null;

        respFrame = socket.ReceiveFrame(out err);

        if (err != null)
        {
            errStr = String.Format("Error while receiving response data {0} {1} {2} {3}", err.Text, err.Number, err.Name, num_messages);
            return false;
        }
        return true;
   }

set the sendTimeout and receiveTimeout on the socket to 2 min each. When I keep calling sendMessage, exactly at the 255th time, receiveFrame timesout . On the server I see the message being processed and response being sent like everytime. And after this point, my send also timesout with the same error "EAGAIN" Resource temporarily unavailable.
There are the things I tried

  1. Data with different lengths from 2 KB to 20 MB
  2. set the sendhighwatermark and receivehighwatermark to different values: 10, 1000, 10000
  3. Tried polling on the socket instead of ReceiveFrame
  4. Tried making the sockets completely blocking.
    In each of the above cases the failure occured at exactly the 255th time. In case of blocking sockets, it got blocked at the 255th time too.
    I also tried a dealer client from another linux machine and it had no issues 255th time or even later.

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

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.

Cannot load .so/.dylib file on Mono/MacOSX/libzmq

Hi

When I use the nuget package on linux I get the following exception. For some reason it is looking in /var for the .so file. I am using this on OSX with Mono and find the same problem, though "copy if newer" and "always copy" do not resolve. Here is what I get when I put the lib...{dll&so} in the folder named here:

[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeInitializationException: The type initializer for 'ZeroMQ.lib.zmq' threw an exception. ---> System.IO.FileNotFoundException: UnmanagedLibrary[libzmq] Unable to load library "libzmq" from "/var/folders/jm/vkm98mmn2pq6gj6ysc3b3xwm0000gn/T/libzmq.so". Inspect Trace output for details.
File name: '/var/folders/jm/vkm98mmn2pq6gj6ysc3b3xwm0000gn/T/libzmq.so' ---> System.DllNotFoundException: dlopen(/var/folders/jm/vkm98mmn2pq6gj6ysc3b3xwm0000gn/T/libzmq.so, 257): no suitable image found. Did find:
/var/folders/jm/vkm98mmn2pq6gj6ysc3b3xwm0000gn/T/libzmq.so: unknown file type, first eight bytes: 0x7F 0x45 0x4C 0x46 0x01 0x01 0x01 0x00
at ZeroMQ.lib.Platform+Posix.LoadUnmanagedLibrary (System.String libraryName) [0x00213] in /Users/tommy/Downloads/clrzmq4-master/lib/Platform.Posix.cs:123
at ZeroMQ.lib.zmq..cctor () [0x005b6] in /Users/tommy/Downloads/clrzmq4-master/lib/zmq.cs:40
--- End of inner exception stack trace ---
at ZeroMQ.ZContext..ctor () [0x00007] in /Users/tommy/Downloads/clrzmq4-master/ZContext.cs:55
at Examples.Program.Main (System.String[] args) [0x00008] in /Users/tommy/Projects/ZMQ_Example/ZMQ_Example/Program.cs:170

windows 7 + VS2013 nuget install failure

Hello!

The nuget page https://www.nuget.org/packages/ZeroMQ/ tells me to use "Install-Package ZeroMQ".

Excepted result:
"Successfully added...."

Actual result:

PM> install-package zeromq
Installing 'ZeroMQ 4.1.0.7'.
You are downloading ZeroMQ from Pieter Hintjens, metadings, the license agreement to which is available at https://raw.githubusercontent.com/zeromq/clrzmq4/master/LICENSE.txt. Check the package for additional dependencies, which may come with their own license agreement(s). Your use of the package and dependencies constitutes your acceptance of their license agreements. If you do not accept the license agreement(s), then delete the relevant components from your device.
Successfully installed 'ZeroMQ 4.1.0.7'.
Adding 'ZeroMQ 4.1.0.7' to ZeroMQ.
Uninstalling 'ZeroMQ 4.1.0.7'.
Successfully uninstalled 'ZeroMQ 4.1.0.7'.
Install failed. Rolling back...
Install-Package : Failed to add reference to 'libsodium'.At line:1 char:1

  • install-package zeromq
  • - CategoryInfo          : NotSpecified: (:) [Install-Package], InvalidOperationException
    - FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PowerShell.Commands.InstallPackageCommand
    
    

It fails even after

PM> install-package libsodium-net -Pre
Attempting to resolve dependency 'Baseclass.Contrib.Nuget.Output'.
Installing 'Baseclass.Contrib.Nuget.Output 1.0.7'.
Successfully installed 'Baseclass.Contrib.Nuget.Output 1.0.7'.
Installing 'libsodium-net 0.7.0-beta2'.
You are downloading libsodium-net from adamcaudill, the license agreement to which is available at https://raw.githubusercontent.com/adamcaudill/libsodium-net/master/LICENSE. Check the package for additional dependencies, which may come with their own license agreement(s). Your use of the package and dependencies constitutes your acceptance of their license agreements. If you do not accept the license agreement(s), then delete the relevant components from your device.
Successfully installed 'libsodium-net 0.7.0-beta2'.
Adding 'Baseclass.Contrib.Nuget.Output 1.0.7' to ZeroMQ.
Successfully added 'Baseclass.Contrib.Nuget.Output 1.0.7' to ZeroMQ.
Adding 'libsodium-net 0.7.0-beta2' to ZeroMQ.
Successfully added 'libsodium-net 0.7.0-beta2' to ZeroMQ.

I've tried to contact the nuget package owner, but the page tells me to use the project site (linked to this github) to contact the owner.

Also I have tried to download the zeromq windows source zip files:

  • 4.1.0 RC - opening the solution gives me error messages that the builds/msvc/properties/Debug.props file is missing (included in the project configuration, but not in the zip files).

  • 4.0.5 zip has msvc10 solution only, which needs upgrading when using VS2013, the upgrade happens automatically, but the build fails with 3 xcopy failed with exit code 4 messages.

    So I'm stuck, no zeromq install method works as expected, also clrmq 3.0 is a ~2-3 years old beta, and the articles about installation are 3 years old and none works with win7 x64 vs2013 in any ways.

UPDATE: "nuget.exe install zeromq" looks fine ("Successfully installed ZeroMq 4.1.0.7" - even if it's not officially released yet!). I just can't imageine now why visualstudio nuget fails.

Possibly bad/incomplete libzmq+libsodium DLL:s (Windows)

TL;DR: The libzmq DLL in 4.1.0.21 is incomplete and/or not linking properly with libsodium (libsodium-related functions in libzmq set errno "ENOTSUP"). Suggest fixed libzmq DLL or revert to older version of libzmq DLL.


I am using Visual Studio 2015 (using .NET 4.5.2.), with ZeroMQ/clrzmq4 version 4.1.0.21 (installed with NuGet).

A System.InvalidOperationException is thrown when calling ZeroMQ.Z85.CurveKeypair (and other libsodium dependent functionality). Catching the exception and checking the ZeroMQ.lib.zmq.errno(), "ENOTSUP" is returned. This indicates that the libzmq DLL was built without libsodium/curve support.

A colleague used an earlier version of the ZeroMQ bindings (the exact version escapes me) installed with NuGet. In his case, the call worked fine. Since he was using NET 4.0, we tried to update his ZeroMQ version to 4.1.0.21 to see if the call still worked (it didn't).

Since I figured one of the DLLs where to blame, I tried replacing them with ones I built myself from jedisct1/libsodium and zeromq/libzmq, but it didn't work. It seems libzmq has changed the way in which the DLL builds. According to my colleague it previously linked statically with libsodium (or at least it was a build option), but now that option is gone. When building the libzmq.dll you are left with the libsodium and libzmq dlls where,the libzmq dll does not load or dynamically link with the functions in the libsodium dll.

I basically solved the problem by tweaking the libzmq build by

  1. setting a preprocessor definition that was not set when building libzmq together with libsodium (I think it was ZMQ_HAVE_CURVE). It is not properly set by configure.bat when building for msvc.
  2. making sure to build libzmq.dll and link it to libsodium.lib (this is a dynamic import library containing stubs to load the correpsonding functions in libsodium.dll)

With the new dlls, the call to ZeroMQ.Z85.CurveKeypair call worked. I have only tested this with Visual Studio 2015, so I don't know if the build is broken for all Visual Studio versions (both libzmq and libsodium have separate msvc solutions for each version).

I don't know if there is a way to handle the linking issue directly in ZeroMQ, for example with some kind of interop/dll import trickery.

Hopefully this is not a waste of your time :)

Update to include libzmq 4.1.5

The version of the native DLLs currently in clrzmq4 is a bit out of date - the main ZMQ project has release 4.1.5. It'd be good to update clrzmq4 to use this.

(For reference, the issue I'm having looks very much like zeromq/libzmq#1542 which is fixed in 4.1.5, which is why I'm keen to see an update!)

As it happens, I've tried compiling libzmq myself, but I'm not having much luck. Additionally the Windows binary downloads on http://zeromq.org/distro:microsoft-windows aren't up to date, so there doesn't appear to be an easy way of me getting 4.1.5 binaries from there...

NETCore Compatibility?

ZeroMQ 4.1.0.21 is not compatible with netcoreapp1.0. Is there a plan for NETCore support?

How to use libzmq 4.0.4

Hi,
I installed this binding using NuGet, and it works correctly in my application. Since I wanted to use libzmq 4.0.4 I replaced the libzmq files in folders amd64 and i386, but it did not work, when I run the application I get the following error:

"The composition produced a single composition error.
The root cause is provided below.
Review the CompositionException.Errors property for more detailed information.\r\n\r\n1)
The system cannot find the file specified\r\n\r\nResulting in: UnmanagedLibrary[libzmq] Unable to load library "libzmq"
from "D:\Users\210045196\AppData\Local\Temp\libzmq.dll". .....

Am I missing something?

Thanks,

Teresa

Bug with ZeroMQ.lib.zmq.Version Property in Visual Basic

Because visual basic is not case specific, am getting a: 'version' is ambiguous because multiple kinds of members with this name exist in class error...

These 2 properties will need to be differentiated by more than just the cased v, to work with visual basic.

Actor automatic endpoint generation can result in invalid endpoints

It seems like the code generating the actor endpoint sometimes generate an invalid endpoint. From the testing I did this seems to occur when the generated byte array starts with a zero which is converted to "\0" by the encoder and triggers the error.

In the ZActor constructor code:

        var rnd0 = new byte[8];
        using (var rng = new System.Security.Cryptography.RNGCryptoServiceProvider()) rng.GetBytes(rnd0);
        this.Endpoint = string.Format("inproc://{0}", ZContext.Encoding.GetString(rnd0));

Converting a random bunch of bytes using Encoding is dangerous I think. Using the BitConverter instead seems to solve the problem:

        this.Endpoint = string.Format("inproc://{0}", BitConverter.ToString(rnd0));

Here is some unit test code to trigger the problem with a repeat count of 500. Not guaranteed to trigger it but if you run the test a few times or increase the repeat count you are sure to bump into it. The code commented out implements the BitConverter fix described above and manually specifies the endpoint.

        using (var context = ZContext.Create())
        {
            for (var i = 0; i < 500; i++)
            {
                //var rnd0 = new byte[8];

                //using (var rng = new System.Security.Cryptography.RNGCryptoServiceProvider())
                //    rng.GetBytes(rnd0);

                //var ep = string.Format("inproc://{0}", BitConverter.ToString(rnd0));
                //var actor = new ZActor(context, ep, (ctx, skt, clr, args) => { });

                var actor = new ZActor(context, (ctx, backend, cancellor, args) => { });

                try
                {
                    actor.Start();
                }
                catch (ZException ze)
                {
                    var problem = actor.Endpoint.Substring(9);
                    var bytes = ZContext.Encoding.GetBytes(problem);

                    throw new Exception(string.Format("Exndpoint - {0} ({1})", actor.Endpoint, BitConverter.ToString(bytes)), ze);
                }
                finally
                {
                    actor.Dispose();
                }
            }
        }

Setting encryption keys

I am trying the library and I would like to request some help.

I am using router socket and trying to set encryption keys. I have 40 characters long encryption keys.
Using Z85 to decode and set the keys.

var keybytes = ZeroMQ.Z85.ToZ85DecodedBytes("key")
socket.CurveSecretKey = keybytes;

I set CurveSecretKey, CurvePublicKey, CurveServerKey but when I try to access these keys it gives this error "EINVAL(22): Invalid argument".

The communication between the client app and my router socket doesn't work. If we don't use encryption keys the the communication works. The decoded bytes I am using should be correct they are used in other implementations (not .net)

Thanks.

Segmentation fault when running in MonoDevelop

When running this code in MonoDevelop (4.0.12), using Mono/.net 4.0 as target:

private void buttonStart_Click(object sender, EventArgs e)
        {
            if (!bRunning)
            {
                ZContext context = ZContext.Create();
                using (var worker = new ZSocket(context, ZSocketType.DEALER)) 
                                {
                                }
            }
        }

I get a segmentation fault at the ZContext.Create():
at <0xffffffff>
at (wrapper managed-to-native) ZeroMQ.lib.Platform/Posix.dlopen (intptr,int) IL 0x00036, 0xffffffff
at ZeroMQ.lib.Platform/Posix.OpenHandle (string) IL 0x0000d, 0x0004f
at ZeroMQ.lib.Platform/Posix.LoadUnmanagedLibrary (string) IL 0x00113, 0x0049b

This happens with precompiled binaries and the same thing happens if I compile the source myself. When singlestepping it seems to happens when it tries to load the sodium library (which is installed correctly)

I'm running on a 32-bit Debian installation.

RRBroker: ZException: EFAULT(14): Bad address

var frontend = ZSocket.Create(context, ZSocketType.ROUTER);

has a following exception:
EFAULT(14): Bad address
at ZeroMQ.ZSocket..ctor(ZContext context, ZSocketType socketType)
at ZeroMQ.ZSocket.Create(ZContext context, ZSocketType socketType)

The code is basically following http://zguide.zeromq.org/cs:rrbroker, not sure if it's useful, but I started the broker in its own thread. I wanted to suspect if it was the endpoint string problem, but it seems this exception happened even before passing any endpoint to the socket.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.