Skip to content

louis49/SocketIO-Objc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Socket.IO / Objective C Library

** This version only support Socket.io v1.X.X **

Support Features :

  • Ack
  • Binary Data
  • Binary Ack
  • Namespace

run "Server" Target then SocketIO-ObjC-Exemple to run some test usage methods

Inspired by :

Usage

The easiest way to connect to your Socket.IO / node.js server is

SocketIO * socketGlobal = [[SocketIO alloc] initWithDelegate:self host:@"localhost" port:8080 namespace:nil timeout:1000 secured:NO];
[socketGlobal connect];

You can use Namespace :

SocketIO * socketPublic = [[SocketIO alloc] initWithDelegate:self host:@"localhost" port:8080 namespace:@"/public" timeout:1000 secured:NO];
[socketPublic connect];

You can send extra-data during connexion :

SocketIO * socketPrivate = [[SocketIO alloc] initWithDelegate:self host:@"localhost" port:8080 namespace:@"/private" timeout:1000 secured:NO];
[socketPrivate connectWithParams:@{@"login": @"fail"}];

Sending Data :

- (void) sendMessage:(id)data;
- (void) sendMessage:(id)data ack:(SocketIOCallback)function;
- (void) sendEvent:(NSString *)eventName data:(id)data;
- (void) sendEvent:(NSString *)eventName data:(id)data ack:(SocketIOCallback)function;

"(id)data" can be NSString, NSData, NSArray, NSDictionnary

Receiving Data :

- (void) socketIO:(SocketIO *)socket didReceiveMessage:(id)data ack:(SocketIOCallback)function;
- (void) socketIO:(SocketIO *)socket didReceiveEvent:(NSString *)eventName data:(id)data ack:(SocketIOCallback)function;

if "ack" is not nil you can answer to the server with a binary or simple ack:

function([@"Binary Ack" dataUsingEncoding:NSASCIIStringEncoding]);
OR
function(@"Simple Ack");

Sending Stream :

SocketIOOutputStream * stream = [[SocketIOOutputStream alloc] initWithSocket:socket];
[stream setDelegate:self];
[socket sendStream:stream1  name:@"Send Stream" extradata:nil];
OR
[socket sendStreams:@[stream]  name:@"Send Stream" extradata:nil];

Then, implement this delegate to "push" data when asked :

- (void) stream:(SocketIOOutputStream*)stream askData:(NSUInteger)length;

Receiving Stream : Implement this delegate and read data :

- (void) socketIO:(SocketIO *)socket didReceiveStream:(SocketIOInputStream *)stream
{
	[stream setDelegate:self];
	if (![stream isFinished])
		[stream readLength:1024];
}

Then, implement this delegate to read data when received and ask more data :

- (void) stream:(SocketIOInputStream*)stream didReceiveData:(NSData*)data
{
	// Read Data

	if (![stream isFinished])
		[stream readLength:1024];
}

When there is no more data this delegate is called:

- (void) streamDidFinish:(SocketIOInputStream*)stream;

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published