Binary iOS

Binary Streams for iOS

View the Project on GitHub mattneary/binary-ios

Binary iOS is a port of the Binary.js library for transmission of binary data over web sockets. It serves as a platform for powerful, realtime applications.

Setup

Frameworks and Sources

Usage

Include StreamClient.h:

#import "StreamClient.h"

Create a client to a websocket, set to an instance variable then set a delegate and open:

- (void)viewWillAppear:(BOOL)animated {
    _client = [StreamClient clientWithAddress:[NSURL URLWithString:@"ws://filepiper.com/abcd"]];
    _client.delegate = self;
    [_client openClient];
}

Abide to StreamClientDelegate Protocol:

@protocol StreamClientDelegate <NSObject>
- (void)streamCreated: (BinaryStream *)stream withMeta: (id)meta;
@optional
- (void)clientOpened;
- (void)clientClosedWithCode:(NSInteger)code reason:(NSString *)reason wasClean:(BOOL)wasClean;
- (void)clientErred: (NSError *)error;
@end

When handling created streams, a delegate should follow the StreamDelegate protocol:

@protocol StreamDelegate <NSObject>
- (void)streamGotData: (id)data;
- (void)streamGotError: (NSError *)error;
- (void)streamEnded;
@end

Create, write to, listen to, end, and pipe streams as you please. Use the FileReadStream and FileWriteStream which are file interfaces following the same protocols as BinaryStreams:

@protocol WriteStream <NSObject>
- (void)write: (id)data;
- (void)end;
@optional
- (void)pause;  //TODO
- (void)resume; //TODO
@end

@protocol ReadStream <NSObject>
- (void)open;
@optional
- (void)pipe: (NSObject<WriteStream> *)destination;
- (void)pause;  //TODO
- (void)resume; //TODO
@end