Skip to content

Instantly share code, notes, and snippets.

@somdoron
somdoron / gist:4183132
Created December 1, 2012 16:33
connect performance
static void Main(string[] args)
{
using (Context context = Context.Create())
{
using (var socket1 = context.CreateResponseSocket())
{
socket1.Bind("tcp://127.0.0.1:82");
while (true)
using (NetMQContext ctx = NetMQContext.Create())
{
using (var server = ctx.CreateResponseSocket())
{
server.Bind("tcp://127.0.0.1:5556");
using (var client = ctx.CreateRequestSocket())
{
client.Connect("tcp://127.0.0.1:5556");
[Test]
public void InProcWorkers()
{
int count = 100;
int workers = 10;
using (NetMQContext context = NetMQContext.Create())
{
using (var response = context.CreateResponseSocket())
{
@somdoron
somdoron / clientserver.c
Created August 14, 2015 12:55
Using Client Server socket types with CZMQ
// Create server and client sockets and connect over inproc
zsock_t *server = zsock_new_server ("@inproc://zframe-server.test");
zsock_t *client = zsock_new_client (">inproc://zframe-server.test");
// Send message from client to server
zframe_t frame = zframe_new ("Hello", 5);
int rc = zframe_send (&frame, client, 0);
// Read message
frame = zframe_recv (server);
@somdoron
somdoron / example.c
Last active May 31, 2017 16:29
polling on multiple sockets
void* ctx = zmq_ctx_new();
void* client = zmq_socket(ctx, ZMQ_CLIENT);
// creating new pollfd, pollfd is per thread.
void* pollfd = zmq_pollfd_new();
// associate pollfd with client, you can associate multiple pollfd with one socket for multi threading
zmq_add_pollfd(client, pollfd);
zmq_pollitem_t items[] {
public class Client
{
/// <summary>
/// List of address to connect to. Will connect to the first one responding. Connected address can changed if disconnected.
/// </summary>
public void Connect(IEnumerable<string> addresses)
{
}
int main (void)
{
setup_test_environment ();
int i;
for (i = 0; i < 100; i++)
{
void *ctx = zmq_ctx_new ();
assert (ctx);
@somdoron
somdoron / zstruct.xml
Created January 19, 2016 13:35
zstruct
<class name = "zstruct">
<!--
Copyright (c) the Contributors as noted in the AUTHORS file.
This file is part of CZMQ, the high-level C binding for 0MQ:
http://czmq.zeromq.org.
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
-->
public class Client : MonoBehaviour
{
private SubscriberSocket m_subscriber;
private NetMQContext m_context;
// Use this for initialization
void Start()
{
ForceDotNet.Force();
@somdoron
somdoron / radiodish.c
Last active October 16, 2017 04:11
radiodish
zsock_t *radio = zsock_new_radio ("inproc://zframe-test-radio");
zsock_t *dish = zsock_new_dish ("inproc://zframe-test-radio");
// Use following for multicast
// zsock_t *radio = zsock_new_radio ("udp://239.0.0.1:55555");
// zsock_t *dish = zsock_new_dish ("udp://239.0.0.1:55555");
// Join to group
rc = zsock_join (dish, "World");
assert (rc == 0);