Skip to content

Instantly share code, notes, and snippets.

@rossmartin
Created December 30, 2012 23:32
Show Gist options
  • Save rossmartin/4416004 to your computer and use it in GitHub Desktop.
Save rossmartin/4416004 to your computer and use it in GitHub Desktop.
This is the server socket's didAcceptNewSocket delegate method.
// GCDAsyncSocket delegate, called when the server (device receiving JSON) accepts an incoming client connection. another socket is spawned to handle it.
- (void)socket:(GCDAsyncSocket *)sender didAcceptNewSocket:(GCDAsyncSocket *)newSocket
{
// The "sender" parameter is the listenSocket we created.
// The "newSocket" is a new instance of GCDAsyncSocket.
// It represents the accepted incoming client connection.
// Do server stuff with newSocket...
NSLog(@"Accepted new socket from %@:%hu", [newSocket connectedHost], [newSocket connectedPort]);
NSString *welcomMessage = @"Server says Hi, send me some JSON \r\n";
[newSocket writeData:[welcomMessage dataUsingEncoding:NSUTF8StringEncoding] withTimeout:-1 tag:TAG_ASK_FOR_JSON];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment