1.附件见zeromq-ios.framework百度网盘/iOS/zmq

2.zeromq-ios.framework解压拖进工程文件
3.objc-zmq见百度网盘/iOS/zmq
4.objc-zmq.zip解压拖进工程文件
5.other link flags -lstdc++
6.客户端
#import “ZMQObjC.h"

   ZMQContext *ctx = [[ZMQContext alloc] initWithIOThreads:];

    NSString *endpoint = @"tcp://localhost:5555";

    ZMQSocket *requester = [ctx socketWithType:ZMQ_REQ];

    BOOL didConnect = [requester connectToEndpoint:endpoint];

    if (!didConnect) {

        NSLog(@"*** Failed to connect to endpoint [%@].", endpoint);

        return;

    }

    int kMaxRequest = ;

    NSData *request = [@"Hello" dataUsingEncoding:NSUTF8StringEncoding];

    for (int request_nbr = ; request_nbr < kMaxRequest; ++request_nbr) {

        @autoreleasepool {

            NSLog(@"Sending request %d.", request_nbr);

            [requester sendData:request withFlags:];

            NSLog(@"Waiting for reply");

            NSData *reply = [requester receiveDataWithFlags:];

            NSString *text = [[NSString alloc] initWithData:reply encoding:NSUTF8StringEncoding];

            NSLog(@"Received reply %d: %@", request_nbr, text);

        }

    }

    [ctx closeSockets];

    [ctx terminate];

7.服务器端

#import “ZMQObjC.h"

    ZMQContext *ctx = [[ZMQContext alloc] initWithIOThreads:];

    NSString *endpoint = @"tcp://*:5555";

    ZMQSocket *responder = [ctx socketWithType:ZMQ_REP];

    BOOL didBind = [responder bindToEndpoint:endpoint];

    if (!didBind) {

        NSLog(@"*** Failed to bind to endpoint [%@].", endpoint);

        return EXIT_FAILURE;

    }

    while () {

        @autoreleasepool {

            //  Wait for next request from client

            NSData *data = [responder receiveDataWithFlags:];

            //NSData *data = [responder receiveWithBuffer:<#(void *)#> length:<#(size_t)#> flags:<#(ZMQMessageReceiveFlags)#>]

            NSString *text = [[NSString alloc]

                              initWithData:data encoding:NSUTF8StringEncoding];

            NSLog(@"Received request: %@", text);

            //  Do some 'work'

            NSLog(@"do some work");

            sleep ();

            //  Send reply back to client

            NSString *world = @"World";

            NSData *reply = [world dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];

            BOOL ok = [responder sendData:reply withFlags:];

            if (!ok) {

                NSLog(@"failed to reply");

            }

        }

    }

    [ctx terminate];

zmq-ios framwork的更多相关文章

  1. iOS -- CocoaPods

    CocoaPods 是什么? CocoaPods 是一个负责管理 iOS 项目中第三方开源库的工具.CocoaPods 的项目源码在 GitHub( https://github.com/CocoaP ...

  2. IOS 整体架构 和 MVC布局

    IOS的生态系统 IOS生态系统不仅仅是指产品,更重要的是指 iPhone/iPad/iPod/Mac +iCloud+App整个系统,包括Siri (部分设备不支持).FaceTime.Safari ...

  3. ios中的http:get,post,同步,异步

    一.服务端 1.主要结构:

  4. ios 开发中 动态库 与静态库的区别

    使用静态库的好处 1,模块化,分工合作 2,避免少量改动经常导致大量的重复编译连接 3,也可以重用,注意不是共享使用 动态库使用有如下好处: 1使用动态库,可以将最终可执行文件体积缩小 2使用动态库, ...

  5. iOS Orientation bug

    Every September means pain for iOS developers- you need to make sure your old apps/code run on the n ...

  6. 之前总结的今天给大分享一下iOS

    退回输入键盘 苹果 ios 开发一年的工作笔记 - (BOOL) textFieldShouldReturn:(id)textField{ [textField resignFirstResponde ...

  7. ios框架

    iPhone OS(现在叫iOS)是iPhone, iPod touch 和 iPad 设备的操作系统.        1,Core OS: 是用FreeBSD和Mach所改写的Darwin, 是开源 ...

  8. class-dump获取iOS私有api

    转自:http://blog.csdn.net/sunyuanyang625/article/details/41440167 获取各类iOS私有api 安装工具class-dump 资源地址http ...

  9. IOS学习笔记25—HTTP操作之ASIHTTPRequest

    IOS学习笔记25—HTTP操作之ASIHTTPRequest 分类: iOS2012-08-12 10:04 7734人阅读 评论(3) 收藏 举报 iosios5网络wrapper框架新浪微博 A ...

随机推荐

  1. webpack 教程 那些事儿02-从零开始

    接着上篇我们有了最简单的安装了webpack的项目目录这节我们从零开始搭建一个简单的基于webpack的spa应用demo本节只说基础常用配置项,复杂后续讲解. 文章目录 1. 新建项目结构目录,如下 ...

  2. 导航栏的坑 (导航透明/导航除线/titleIView)

    //以下四个条件缺一不可 /.必须是半透明状态 self.navigationBar.translucent = YES; //2.导航栏背景图片为空图片 (不可以设置backgroundColor或 ...

  3. HTML5 localStorage 的使用

      在前端开发中,我们会常遇到要在两个甚至多个html之间通信,我们可以在url中添加参数,但是当要传递的数据量较大较多时呢,不妨试试html5 的localStorage吧. 1) 检测你的浏览器是 ...

  4. How to tile small texture image onto page as its background

    You don’t need to set a big size image as the background of pages if the image is texture or uniform ...

  5. mysql远程登录权限修改ubuntu

    mysql默认只允许在localhost主机登录,如果想要通过远程登录管理,需要修改相应的权限. 方法一 首先:开启mysql所在主机的3306端口,或者关闭防火墙. service iptables ...

  6. 3.3---集合栈(CC150)

    思路:注意一下别写错add还是remove public class SetOfStacks { public static ArrayList<ArrayList<Integer> ...

  7. url中出现井号("#")的问题

    今天在asp.net mvc网站项目的前台页面里写一段js代码时,想要跳转到某个url,例如 location.href="xxxx?"+"id="+id+&q ...

  8. 小波变换C++实现(一)----单层小波变换

    文章转自: http://www.cnblogs.com/IDoIUnderstand/archive/2013/03/30/3280724.html [小波变换]STL版 一维离散小波变换(DWT) ...

  9. Shell 脚本 ,, 根据进程号退出 从而关机

    #!/bin/bash fun(){ ps -ef | grep "$1" | awk '{print $2 $8}' > /usr/file while read line ...

  10. centos7.0改变用户创建目录组权限

    centos7.0改变用户创建目录组权限可通过umask进行设置. 临时改变可通过umask命令进行设置 永久性改变,可通过修改~/.bash_profile的方式进行调整.