Re: Create a socket.io connection to node.js server
Re: Create a socket.io connection to node.js server
- Subject: Re: Create a socket.io connection to node.js server
- From: Vavelin Kévin <email@hidden>
- Date: Fri, 07 Dec 2012 20:04:56 +0100
Yes I understand, I use NSInputStream and NSOutputStream for writing something but I don't know why I have my stream closed after an event hasSpaceAvailable or something like that. Here's my code and I send nothing to my stream.
- (void) initNetworkCommunication
{
CFReadStreamRefreadStream = nil;
CFWriteStreamRefwriteStream = nil;
CFStreamCreatePairWithSocketToHost(kCFAllocatorDefault, (CFStringRef)@"neventy.fr", 80, &readStream, &writeStream);
inputStream = (NSInputStream *)readStream;
outputStream = (NSOutputStream *)writeStream;
[inputStreamsetDelegate:self];
[outputStreamsetDelegate:self];
[inputStreamscheduleInRunLoop:[NSRunLoopcurrentRunLoop]forMode:NSDefaultRunLoopMode];
[outputStreamscheduleInRunLoop:[NSRunLoopcurrentRunLoop]forMode:NSDefaultRunLoopMode];
[inputStream open];
[outputStream open];
}
- (void)stream:(NSStream*)theStream handleEvent:(NSStreamEvent)streamEvent
{
NSLog(@"stream event %i", streamEvent);
NSMutableData *_data;
switch (streamEvent) {
caseNSStreamEventNone:
NSLog(@"Aucun event");
break;
caseNSStreamEventOpenCompleted:
NSLog(@"Stream opened");
break;
caseNSStreamEventHasBytesAvailable:
if(!_data) {
_data = [[NSMutableData data] retain];
}
uint8_tbuf[1024];
unsignedint len = 0;
len = [(NSInputStream *)inputStreamread:buf maxLength:1024];
if(len) {
[_data appendBytes:(const void*)buf length:len];
} else {
NSLog(@"no buffer!");
}
break;
caseNSStreamEventHasSpaceAvailable :
NSLog(@"Espace");
NSLog(@"%@",outputStream);
break;
caseNSStreamEventErrorOccurred:
NSLog(@"Can not connect to the host!");
break;
caseNSStreamEventEndEncountered:
NSLog(@"Erreur");
[theStreamclose];
[theStreamremoveFromRunLoop:[NSRunLoopcurrentRunLoop]forMode:NSDefaultRunLoopMode];
[theStreamrelease];
theStream = nil;
break;
default:
NSLog(@"Unknown event");
}
}
Vavelin Kévin
Twitter | Blog | LinkedIn
Entrepreneur
Developer OS X / iOS
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden