zeromq-ios-py /

Filename Size Date modified Message
GeventServer
ZeroMQTest
103 B
3.2 KB
2.2 KB
856 B

ZeroMQ between iOS and Python

Introduction

This is a ZeroMQ example where an iOS app written in Objective-C talks to a server written in Python with gevent. It doesn't do anything very much: the Python server sends updates over a PUB/SUB socket, the iOS app listens to them and sends requests over a REQ/REP socket when a button is pressed. It has three purposes:

  • It was an excuse to play with ZeroMQ and gevent
  • It provides examples how to use ZeroMQ in iOS and with gevent
  • It contains an (at the moment) up to date script for building a fat iOS library for armv7 and i386

Requirements

The system assumes the following platform which is a prerequisite for running it:

  • OS X 10.7.3
  • Xcode 4.3.2
  • iOS SDK 5.1
  • Python 2.7 (as shipped with OS X)
  • libevent 2.0.18 (I used the package from Homebrew)
  • pip 1.1
  • virtualenv 1.7.1.2

In addition to the bits listed above, the build system fetches the following during the build process:

  • ZeroMQ 2.2.0
  • objc-zmq f5e254a6d8671a463995c6c6bfc8c62467012b67
  • Cython 0.16
  • gevent 0.13.7
  • gevent-zeromq 0.2.2
  • greenlet 0.3.4
  • pyzmq-static 2.1.7.1
  • wsgiref 0.1.2

That's a lot of external dependencies, but they should just automatically work (with one caveat, see the Build section below.) The infrastructure hosting them will sooner or later break, of course.

Because this is just a toy, I have made no effort to find out if it works on different versions of the tools. I also don't really expect that I'll be keeping it very up to date, so if you're running some newer versions of the above don't be surprised if things don't work anymore. If it breaks and you fix it, pull requests will be considered.

Running it

Build

The get-dependencies.sh script should set up the environment you need. It fetches the ZeroMQ sources and builds it for iOS, it fetches objc-zmq and creates the virtualenv sandbox with the required libraries for running the server.

I get an error when the script builds pyzmq-static. It seems to work anyway.

If you get an error at an earlier stage, a good point to start investigation is to make sure xcode-select points to the correct Xcode. The expected output in the most common configuration looks like this:

$ xcode-select -print-path
/Applications/Xcode.app/Contents/Developer

You can also inspect zeromq-2.2.0/build/build.log.

Server

If the script finished successfully, you can run the server:

cd GeventServer
source gsenv/bin/activate
gs/server.py

If you want to specify something other than *:5555 and *:5556 as the endpoints to bind, run server.py with the flag --help to see command line options.

Client

Open the ZeroMQTest/ZeroMQTest.xcodeproj in Xcode. You only need to care about the application delegate in the file ZTAppDelegate.m. If you run the app in the simulator and you didn't change the endpoints used by the server, you should be able to just run the application. If you changed the endpoints or are running on a device, you can adjust the constants kServerIP, kReqPort and kSubPort near the start of the file.

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.