Objective-C
Objective-C
Move a Connection into Another Socket
See more Socket/SSL/TLS Examples
Demonstrates Socket.TakeConnection, which moves the active connection from one Socket into another. The receiving object first releases any connection it previously held.
Background. Unlike TakeSocket, TakeConnection does not add a member to a socket set. After success, the source socket holds no connection. This is useful for handing an accepted connection to a dedicated handler object.
Chilkat Objective-C Downloads
#import <CkoSocket.h>
BOOL success = NO;
CkoSocket *listenSock = [[CkoSocket alloc] init];
success = [listenSock BindAndListen: [NSNumber numberWithInt: 5000] backlog: [NSNumber numberWithInt: 25]];
if (success == NO) {
NSLog(@"%@",listenSock.LastErrorText);
return;
}
CkoSocket *connectedSock = [[CkoSocket alloc] init];
success = [listenSock AcceptNext: [NSNumber numberWithInt: 20000] socket: connectedSock];
if (success == NO) {
NSLog(@"%@",listenSock.LastErrorText);
return;
}
// Move the active connection out of connectedSock and into another Socket object. Unlike
// TakeSocket, this does not add a member to a socket set. After success, connectedSock holds no
// connection.
CkoSocket *handlerSock = [[CkoSocket alloc] init];
success = [handlerSock TakeConnection: connectedSock];
if (success == NO) {
NSLog(@"%@",handlerSock.LastErrorText);
return;
}
NSLog(@"%@",@"Connection moved to the handler socket.");