ZeroMQ between iOS and Python
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
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 188.8.131.52
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 184.108.40.206
- 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.
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
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
*:5556 as the endpoints to bind, run
server.py with the flag
--help to see command line options.
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
kSubPort near the start of the file.