https://github.com/5monkeys/socker-ios
An iOS socker client for handling multiple channels on a single websocket connection
https://github.com/5monkeys/socker-ios
Last synced: 11 months ago
JSON representation
An iOS socker client for handling multiple channels on a single websocket connection
- Host: GitHub
- URL: https://github.com/5monkeys/socker-ios
- Owner: 5monkeys
- License: mit
- Created: 2015-09-29T19:57:28.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2015-12-16T16:23:56.000Z (over 10 years ago)
- Last Synced: 2025-06-30T14:18:59.346Z (12 months ago)
- Language: Objective-C
- Homepage:
- Size: 0 Bytes
- Stars: 2
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Socker iOS client
============
[](https://travis-ci.org/5monkeys/socker-ios)
An iOS client for communicating with a [socker](https://github.com/5monkeys/socker) websocket server which supports subscribing on multiple channels on a single connection. It is based on the very good [SocketRocket](https://github.com/square/SocketRocket) library.
## Installation
Add the following to your `Podfile` and run `pod install`
```bash
pod 'FMSocker'
```
## Usage
Import the library:
```objective-c
#import
```
Initiate the client with a url to your socker server:
```objective-c
FMSockerClient *sockerClient = [[FMSockerClient alloc] initWithURL:[NSURL URLWithString:@"wss://example.com"]];
// Connect to the server
[sockerClient connect];
```
Subscribe on channels:
```objective-c
// Subscribe on foo channel
[sockerClient subscribeOnChannel:@"foo"
onMessage:^(FMSockerMessage *message, NSError *error){
if (!error) {
NSLog(@"Got message on channel %@ with payload %@", message.name, message.data);
} else {
NSLog(@"Failed to parse message %@", [error localizedDescription]);
}
}];
// Subscribe on bar channel
[sockerClient subscribeOnChannel:@"bar"
onMessage:^(FMSockerMessage *message, NSError *error){
if (!error) {
NSLog(@"Got message on channel %@ with payload %@", message.name, message.data);
} else {
NSLog(@"Failed to parse message %@", [error localizedDescription]);
}
}];
```
Send messages:
```objective-c
// Create a socker message
FMSockerMessage *message = [[FMSockerMessage alloc] initWithName:@"testchannel" andData:@[ @"foo", @"bar" ]];
// Initiate the client with a url to your socker server
FMSockerClient *sockerClient = [[FMSockerClient alloc] initWithURL:[NSURL URLWithString:@"wss://example.com"]];
// Connect to the server
[sockerClient connect];
// Send the message
NSError *error;
[sockerClient sendSockerMessage:message error:&error];
```
Unsubscribe channels:
```objective-c
// Unsubscribe channel named foo
[sockerClient unsubscribeChannel:@"foo"];
```
Unsubscribe all channels:
```objective-c
[sockerClient unsubscribeAll];
```
Disconnect websocket:
```objective-c
[sockerClient disconnect];
```