NetMQ


NetMQ 是 ZeroMQ的C#移植版本。

ZeroMQ是一个轻量级的消息内核,它是对标准socket接口的扩展。它提供了一种异步消息队列,多消息模式,消息过滤(订阅),对多种传输协议的无缝访问。

NetMQ 也是一个社区开源项目,网站在Github上 https://github.com/zeromq/netmq, 可以通过Nuget包获取http://nuget.org/packages/NetMQ。

  • 是一个并发框架.
  • 支持通过进程内(Inproc),进程间(IPC), TCP, 和多播来传递消息.
  • 支持多对多的列表、发布/订阅、管道和接收/回复连接.
  • 支持异步.

C# 客户端服务端

Server.cs

public static void Main (string[] args)
  {
        using (NetMQContext context = NetMQContext.Create())
        {
            Server(context);
        }
   }

    static void Server(NetMQContext context)
    {
        using (NetMQSocket serverSocket = context.CreateResponseSocket())
        {
            serverSocket.Bind("tcp://*:5555");

            while (true)
            {
                string message = serverSocket.ReceiveString();

                Console.WriteLine("Receive message {0}", message);

                serverSocket.Send("World");

                if (message == "exit")
                {
                    break;
                }
            }
        }
    }


Client.cs

public static void Main (string[] args)
    {
        using (NetMQContext context = NetMQContext.Create())
        {
            Client(context);
        }

   }

    static void Client(NetMQContext context)
    {
        using (NetMQSocket clientSocket = context.CreateRequestSocket())
        {
            clientSocket.Connect("tcp://127.0.0.1:5555");

            while (true)
            {
                Console.WriteLine("Please enter your message:");
                string message = Console.ReadLine();
                clientSocket.Send(message);

                string answer = clientSocket.ReceiveString();

                Console.WriteLine("Answer from server: {0}", answer);

                if (message == "exit")
                {
                    break;
                }
            }
        }
    }

NetMQ也支持Mono,下面是在Mono上的运行:

站内公告

A PHP Error was encountered

Severity: Core Warning

Message: PHP Startup: zip: Unable to initialize module Module compiled with module API=20060613 PHP compiled with module API=20090626 These options need to match

Filename: Unknown

Line Number: 0

Backtrace: