I am trying to create a simple TCP connection in native code that is running in a titanium module. The code below works perfectly in an xcode project as long as it is NOT a Titanium module.. When it is a titanium module it seems that no stream events ever hit.. My module has just 4 files and was created with the instructions for doing so. I just added the code to do the tcp connection and it doesn't work.. Any ideas?
- (void)initNetworkCommunication {
CFReadStreamRef readStream;
CFWriteStreamRef writeStream;
CFStreamCreatePairWithSocketToHost(NULL, (CFStringRef)@"google.com", 80, &readStream, &writeStream);
inputStream = (NSInputStream *)readStream;
outputStream = (NSOutputStream *)writeStream;
[inputStream setDelegate:self];
[outputStream setDelegate:self];
[inputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[outputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[inputStream open];
[outputStream open];
}
- (void)stream:(NSStream *)theStream handleEvent:(NSStreamEvent)streamEvent {
NSLog(@"stream event %i", streamEvent);
[self fireEvent:@"dexstatus" withObject:@"Stream Event" withSource:@"1st Stream Event"];
switch (streamEvent) {
case NSStreamEventOpenCompleted:
{
NSLog(@"Stream opened");
//NSString *output = @"Wisnap device connected";
//self.label.text = output;
[self setConnected:true];
}
break;
case NSStreamEventHasBytesAvailable:
{
NSLog(@"Bytes Rxed");
}
break;
case NSStreamEventErrorOccurred:
NSLog(@"Can not connect to the host!");
[self setConnected:false];
break;
case NSStreamEventEndEncountered:
NSLog(@"Stream event End");
[self setConnected:false];
[theStream close];
[theStream removeFromRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
//[theStream release];
theStream = nil;
break;
default:
NSLog(@"Unknown event");
}
}
↧