Created
December 30, 2012 23:32
-
-
Save rossmartin/4416004 to your computer and use it in GitHub Desktop.
This is the server socket's didAcceptNewSocket delegate method.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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