Hello I'm trying to use the following cocoa pod for tcp functionality in ios: https://cocoapods.org/pods/CocoaAsyncSocket
Im facing problems writing the marshalled js using this library
Here is an example (Objective C):
// The most common way to initialize an instance is simply like this:
socket = [[GCDAsyncSocket alloc] initWithDelegate:self delegateQueue:dispatch_get_main_queue()];
NSError *err = nil;
if (![socket connectToHost:@"deusty.com" onPort:80 error:&err]) // Asynchronous!
{
// If there was an error, it's likely something like "already connected" or "no delegate set"
NSLog(@"I goofed: %@", err);
}
- (void)socket:(GCDAsyncSocket *)sender didConnectToHost:(NSString *)host port:(UInt16)port
{
NSLog(@"Cool, I'm connected! That was easy.");
}
JSCODE:
// mainQueue var is to get dispatch_get_main_queue
var mainQueue = (function() {
var runloop = CFRunLoopGetMain();
return function(func) {
CFRunLoopPerformBlock(runloop, kCFRunLoopDefaultMode, func);
CFRunLoopWakeUp(runloop);
}
}());
var tcpClient = GCDAsyncSocket.alloc().initWithDelegateDelegateQueue(testerClass,mainQueue);
var e = new interop.Reference();
if (!tcpClient.connectToHostOnPortError('192.168.88.110',3333,e)) {
console.log('Could not connect to mipbook');
console.log(e.value);
}
function socketDidConnectToHost(sock,host,port) {
console.log('connected to host');
}
The connect to port part is working fine, but the delegate instance method is not being called when the connection is successful.