/socketio-cocoa

Cocoa interface to Socket.IO by way of WebSockets.

Primary LanguageObjective-Czlib LicenseZlib

This library does not work with Socket.IO 0.7. Philipp Kyeck has created another library that does - socket.IO-objc

Socket.IO Client for Cocoa

A Cocoa interface to Socket.IO by way of web sockets. If you're already using Socket.IO stuff for your web site, you might find it convenient to use the same architecture for your mobile stuff, too.

We use this with juggernaut-cocoa to work with Juggernaut, a realtime/push service based on Socket.IO.

Usage

SocketIoClient *client = [[SocketIoClient alloc] initWithHost:host port:port];
client.delegate = self;

[client connect];

[client send:@"Hello Socket.IO" isJSON:NO];

You'll get sweet callbacks on your delegate when stuff goes down...

- (void)socketIoClientDidConnect:(SocketIoClient *)client {
    NSLog(@"Connected.");
}

- (void)socketIoClientDidDisconnect:(SocketIoClient *)client {
    NSLog(@"Disconnected.");
}

- (void)socketIoClient:(SocketIoClient *)client didReceiveMessage:(NSString *)message isJSON:(BOOL)isJSON {
    NSLog(@"Received: %@", message);
}

And, of course, all the normal heartbeat / reconnection stuff will happen for you behind the scenes.

Depends on

Getting the code

If you have git 1.7+ ...

git clone git://github.com/fpotter/socketio-cocoa.git --recursive

or, earlier...

git clone git://github.com/fpotter/socketio-cocoa.git socketio-cocoa
cd socketio-cocoa
git submodule init
git submodule update

Adding to your project

Copy the AsyncSocket.h, AsyncSocket.m, WebSocket.h, WebSocket.m, SocketIoClient.h, SocketIoClient.m files to your project.

If you're building for iOS, make sure you add a reference to the CFNetwork framework or you'll see compile errors from AsyncSocket.