A simple WebSocket server
RockemSockem isn’t just an awesome name. It’s a super-simple, ReactiveCocoa-based WebSocket server for OS X.
It uses CocoaHTTPServer to do all the hard stuff. Because the hard stuff is hard. Basically all the credit goes to them.
server = [[RSMServer alloc] init];
server.port = 12345;
server.interface = @"localhost";
[server.webSockets subscribeNext:^(RSMWebSocket *socket) {
[socket sendMessage:@"Sock it to me."];
[socket.messages subscribeNext:^(NSString *message) {
NSLog(@"Got \"%@\" from %@", message, socket);
}];
}];
NSError *error;
BOOL success = [server start:&error];
if (!success) {
NSLog(@"Error starting server: %@", error);
}
See RockemSockemSample for a slightly complete example.
If you’re developing RockemSockem on its own, then simply open RockemSockem.xcworkspace
.
If you’re running a WebSocker server on iOS I feel bad for you son. I got 99 problems and RockemSockem not running on iOS ain’t one. (Pull requests welcome.)