Objective-C
Objective-C
Move a Connection into a Socket Set
See more Socket/SSL/TLS Examples
Demonstrates Socket.TakeSocket, which moves a connection into a newly created member of this object's socket set. After one or more calls, the object acts as a set of sockets.
Background. A socket set groups multiple connections so they can be monitored together with the SelectForReading and SelectForWriting methods. After success, the source socket holds no connection.
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 connection out of connectedSock and into a newly created member of this object's socket
// set. After one or more such calls, socketSet acts as a set of connected sockets (useful with the
// SelectForReading / SelectForWriting methods). After success, connectedSock holds no connection.
CkoSocket *socketSet = [[CkoSocket alloc] init];
success = [socketSet TakeSocket: connectedSock];
if (success == NO) {
NSLog(@"%@",socketSet.LastErrorText);
return;
}
NSLog(@"%@",@"Connection added to the socket set.");