{"id":19973227,"url":"https://github.com/zeromq/clrzmq4","last_synced_at":"2025-05-16T14:05:21.028Z","repository":{"id":25595224,"uuid":"29029912","full_name":"zeromq/clrzmq4","owner":"zeromq","description":"ZeroMQ C# namespace (.NET and mono, Windows, Linux and MacOSX, x86 and amd64)","archived":false,"fork":false,"pushed_at":"2022-03-29T16:52:27.000Z","size":35084,"stargazers_count":243,"open_issues_count":21,"forks_count":112,"subscribers_count":39,"default_branch":"master","last_synced_at":"2025-05-13T08:07:15.132Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zeromq.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-01-09T18:40:43.000Z","updated_at":"2025-04-17T11:59:21.000Z","dependencies_parsed_at":"2022-07-10T12:16:48.151Z","dependency_job_id":null,"html_url":"https://github.com/zeromq/clrzmq4","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zeromq%2Fclrzmq4","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zeromq%2Fclrzmq4/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zeromq%2Fclrzmq4/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zeromq%2Fclrzmq4/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zeromq","download_url":"https://codeload.github.com/zeromq/clrzmq4/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254544146,"owners_count":22088807,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-13T03:10:42.163Z","updated_at":"2025-05-16T14:05:21.005Z","avatar_url":"https://github.com/zeromq.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n[![Build Status](https://travis-ci.org/zeromq/clrzmq4.svg?branch=master)](https://travis-ci.org/zeromq/clrzmq4) [![Build status](https://ci.appveyor.com/api/projects/status/102sf149379bgwv7/branch/master?svg=true)](https://ci.appveyor.com/project/zeromq/clrzmq4/branch/master)\n\n**ZeroMQ C# library**\n\nclrzmq4 is a .NET wrapper around the native [ZeroMQ/libzmq](https://github.com/zeromq/libzmq) library, and\nprovides the ZeroMQ namespace.\n\nIt is written in C# 5.0, and can be opened and built using Visual Studio 2012+ and MonoDevelop 5+.\n\nIt is built as AnyCPU to run on .NET Framework 4.0+ and mono 5+, and can currently load native shared libraries for\ni386 and amd64 on Windows, GNU/Linux and Mac OS X.\n\nThe pre-built [nuget.org/packages/ZeroMQ/](https://www.nuget.org/packages/ZeroMQ/) includes native shared libraries for Windows (libzmq 4.1.n) and GNU/Linux (libzmq 4.1.n), for Windows i386 and linux/MacOSX x86_64 architectures.\n\nYou can place any native shared library or dynamic link libraries into a folder ~/Downloads/clrzmq4/amd64 or ~/Downloads/clrzmq4/i386, any libzmq.dll/.so/.dylib 3.x 4.x will work, important is just that the file name is `libzmq.dll`.\n\n```\n    sudo apt-get install libzmq3-dev\n```\n\nGet it\n- by [downloading the Release](https://github.com/zeromq/clrzmq4/releases)\n- using `git clone https://github.com/zeromq/clrzmq4`\n- using [nuget](https://www.nuget.org/packages/ZeroMQ/) `PM\u003e Install-Package ZeroMQ` or by [downloading the nupkg](https://www.nuget.org/api/v2/package/ZeroMQ/)\n\nOpen it\n- using MonoDevelop or Visual Studio\n- using Texteditor gedit or GNU emacs\n\nRun it\n- You can't run ZeroMQ/clrzmq4 directly, because this is a library.\n- using mono framework:\n```\nmsbuild clrzmq4.mono.sln /p:Configuration=Release\nmono bin/Release/ZGuideExamples.exe Espresso\n```\n- using dotnet framwork\n```\nnuget restore clrzmq4.netcore.sln\ndotnet msbuild clrzmq4.netcore.sln\ndotnet run --project ZGuideExamples/ZGuideExamples.netcore.csproj Espresso\n```\n\nRead [ZeroMQ - The Guide](http://zguide.zeromq.org/cs:all)\n- ZeroMQ - The Guide [Examples in C#](http://github.com/metadings/zguide/tree/master/examples/C%23)\n\nAsk questions on [stackoverflow](http://stackoverflow.com/questions/tagged/c%23+zeromq) using tags `C#` `ZeroMQ` !\n\n#### **[HWClient](https://github.com/metadings/zguide/blob/master/examples/C%23/hwclient.cs) Example**\n```csharp\npublic static void HWClient(string[] args)\n{\n\t//\n\t// Hello World client\n\t//\n\t// Author: metadings\n\t//\n\n\t// Create\n\t// using (var context = new ZContext())\n\tusing (var requester = new ZSocket(ZSocketType.REQ))\n\t{\n\t\t// Connect\n\t\trequester.Connect(\"tcp://127.0.0.1:5555\");\n\n\t\tfor (int n = 0; n \u003c 10; ++n)\n\t\t{\n\t\t\tstring requestText = \"Hello\";\n\t\t\tConsole.Write(\"Sending {0}...\", requestText);\n\n\t\t\t// Send\n\t\t\trequester.Send(new ZFrame(requestText));\n\n\t\t\t// Receive\n\t\t\tusing (ZFrame reply = requester.ReceiveFrame())\n\t\t\t{\n\t\t\t\tConsole.WriteLine(\" Received: {0} {1}!\", requestText, reply.ReadString());\n\t\t\t}\n\t\t}\n\t}\n}\n```\n\n#### **[HWServer](https://github.com/metadings/zguide/blob/master/examples/C%23/hwserver.cs)** Example\n```csharp\npublic static void HWServer(string[] args)\n{\n\t//\n\t// Hello World server\n\t//\n\t// Author: metadings\n\t//\n\n\tif (args == null || args.Length \u003c 1)\n\t{\n\t\tConsole.WriteLine();\n\t\tConsole.WriteLine(\"Usage: ./{0} HWServer [Name]\", AppDomain.CurrentDomain.FriendlyName);\n\t\tConsole.WriteLine();\n\t\tConsole.WriteLine(\"    Name   Your name. Default: World\");\n\t\tConsole.WriteLine();\n\t\targs = new string[] { \"World\" };\n\t}\n\n\tstring name = args[0];\n\n\t// Create\n\t// using (var context = new ZContext())\n\tusing (var responder = new ZSocket(ZSocketType.REP))\n\t{\n\t\t// Bind\n\t\tresponder.Bind(\"tcp://*:5555\");\n\n\t\twhile (true)\n\t\t{\n\t\t\t// Receive\n\t\t\tusing (ZFrame request = responder.ReceiveFrame())\n\t\t\t{\n\t\t\t\tConsole.WriteLine(\"Received {0}\", request.ReadString());\n\n\t\t\t\t// Do some work\n\t\t\t\tThread.Sleep(1);\n\n\t\t\t\t// Send\n\t\t\t\tresponder.Send(new ZFrame(name));\n\t\t\t}\n\t\t}\n\t}\n}\n```\n\n#### **[WUClient](https://github.com/metadings/zguide/blob/master/examples/C%23/wuclient.cs)** Example\n```csharp\npublic static void WUClient(string[] args)\n{\n\t//\n\t// Weather update client\n\t// Connects SUB socket to tcp://localhost:5556\n\t// Collects weather updates and finds avg temp in zipcode\n\t//\n\t// Author: metadings\n\t//\n\n\tif (args == null || args.Length \u003c 2)\n\t{\n\t\tConsole.WriteLine();\n\t\tConsole.WriteLine(\"Usage: ./{0} WUClient [ZipCode] [Endpoint]\", AppDomain.CurrentDomain.FriendlyName);\n\t\tConsole.WriteLine();\n\t\tConsole.WriteLine(\"    ZipCode   The zip code to subscribe. Default is 72622 Nürtingen\");\n\t\tConsole.WriteLine(\"    Endpoint  Where WUClient should connect to.\");\n\t\tConsole.WriteLine(\"              Default is tcp://127.0.0.1:5556\");\n\t\tConsole.WriteLine();\n\t\tif (args.Length \u003c 1)\n\t\t\targs = new string[] { \"72622\", \"tcp://127.0.0.1:5556\" };\n\t\telse\n\t\t\targs = new string[] { args[0], \"tcp://127.0.0.1:5556\" };\n\t}\n\n\t// Socket to talk to server\n\t// using (var context = new ZContext())\n\tusing (var subscriber = new ZSocket(ZSocketType.SUB))\n\t{\n\t\tstring connect_to = args[1];\n\t\tConsole.WriteLine(\"I: Connecting to {0}...\", connect_to);\n\t\tsubscriber.Connect(connect_to);\n\n\t\t// Subscribe to zipcode\n\t\tstring zipCode = args[0];\n\t\tConsole.WriteLine(\"I: Subscribing to zip code {0}...\", zipCode);\n\t\tsubscriber.Subscribe(zipCode);\n\n\t\t// Process 10 updates\n\t\tint i = 0;\n\t\tlong total_temperature = 0;\n\t\tfor (; i \u003c 20; ++i)\n\t\t{\n\t\t\tusing (var replyFrame = subscriber.ReceiveFrame())\n\t\t\t{\n\t\t\t\tstring reply = replyFrame.ReadString();\n\n\t\t\t\tConsole.WriteLine(reply);\n\t\t\t\ttotal_temperature += Convert.ToInt64(reply.Split(' ')[1]);\n\t\t\t}\n\t\t}\n\t\tConsole.WriteLine(\"Average temperature for zipcode '{0}' was {1}°\", zipCode, (total_temperature / i));\n\t}\n}\n```\n\n#### **[WUServer](https://github.com/metadings/zguide/blob/master/examples/C%23/wuserver.cs)** Example\n```csharp\npublic static void WUServer(string[] args)\n{\n\t//\n\t// Weather update server\n\t// Binds PUB socket to tcp://*:5556\n\t// Publishes random weather updates\n\t//\n\t// Author: metadings\n\t//\n\n\t// Prepare our (context and) publisher\n\t// using (var context = new ZContext())\n\tusing (var publisher = new ZSocket(ZSocketType.PUB))\n\t{\n\t\tstring address = \"tcp://*:5556\";\n\t\tConsole.WriteLine(\"I: Publisher.Bind'ing on {0}\", address);\n\t\tpublisher.Bind(address);\n\n\t\t// Initialize random number generator\n\t\tvar rnd = new Random();\n\n\t\twhile (true)\n\t\t{\n\t\t\t// Get values that will fool the boss\n\t\t\tint zipcode = rnd.Next(99999);\n\t\t\tint temperature = rnd.Next(-55, +45);\n\n\t\t\t// Send message to all subscribers\n\t\t\tvar update = string.Format(\"{0:D5} {1}\", zipcode, temperature);\n\t\t\tusing (var updateFrame = new ZFrame(update))\n\t\t\t{\n\t\t\t\tpublisher.Send(updateFrame);\n\t\t\t}\n\t\t}\n\t}\n}\n```\n\nAlso look into the [WUProxy](https://github.com/metadings/zguide/blob/master/examples/C%23/wuproxy.cs) Example.\n\nLearn more: ZeroMQ - [The Guide](http://zguide.zeromq.org/cs:all) and the [Examples in C#](http://github.com/metadings/zguide/tree/master/examples/C%23)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzeromq%2Fclrzmq4","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzeromq%2Fclrzmq4","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzeromq%2Fclrzmq4/lists"}