Skip to content

makeandship/MSServerSentEvents

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MSServerSentEvents

CI Status Version License Platform

An Objective-C implementation of Server-Sent Events

Usage

Simply initialise an event source and then subscribe to receive events:

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:@"http://127.0.0.1:8888/"];

MSServerSentEventsSource *serverSentEventsSource = [[MSServerSentEventsSource alloc] initWithRequest:request receive:^(MSServerSentEvent *event) {
	NSLog(@"received:%@",event);
}
completion:^{
	NSLog(@"closed");
}
failure:^(NSError *error) {
	NSLog(@"error:%@",error);
}];

[serverSentEventsSource addListenerForEvent:@"open" usingBlock:^(MSServerSentEvent *event) {
	NSLog(@"received open event");
}];

[serverSentEventsSource addListenerForEvent:@"message" usingBlock:^(MSServerSentEvent *event) {
	NSLog(@"received message event");
}];

Installation

MSServerSentEvents is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "MSServerSentEvents"

Author

Simon Heys, [email protected]

License

MSServerSentEvents is available under the MIT license. See the LICENSE file for more info.