[zeromq-dev] I've written a completely new C# API for ZeroMQ

Thomas Fee angrydog at hotmail.com
Wed May 2 07:18:19 CEST 2012


Hey Alex, sounds great but no way I can get it to work. It's probably because 
I'm a newb at this C# stuff. Would appreciate a quick look at this, a cut and 
paste of your code into a program "shell". At this point, I'm just trying to get 
it to compile, never mind have it work.

What I did was copy the DLL (that came with your distro) into my C# project 
directory. Then in Solution Explorer, I added your DLL as a reference (using 
"Add Reference", then Browse tab).

The compile error I get is

'ZeroMQ.ZmqSocket.Bind(string)' is inaccessible due to its protection level

Ditto for .Connect(string).

What does this mean? Would be great if you could write a beginner's tutorial. :-
)

Here is the code:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ZeroMQ;

namespace WpfApplication1
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            var publisher = new ZmqPublishSocket
            {
                Identity = Guid.NewGuid().ToByteArray(),
                RecoverySeconds = 10
            };

            publisher.Bind(address: "tcp://127.0.0.1:9292");
            var subscriber = new ZmqSubscribeSocket();
            subscriber.Connect(address: "tcp://127.0.0.1:9292");
            subscriber.Subscribe(prefix: ""); // subscribe to all messages
            subscriber.OnReceive += () =>
            {
                String message;
                subscriber.Receive(out message, nonblocking: true);
                Console.WriteLine(message);
            };

            publisher.Send("Hello world!");
            return 0;
        }
    }
}





More information about the zeromq-dev mailing list