/ Published in: Objective C
da testare
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
if (![urlStr isEqualToString:@""]) { if (!website) { NSLog(@"%@ is not a valid URL"); return; } [iStream retain]; [oStream retain]; [iStream setDelegate:self]; [oStream setDelegate:self]; [iStream open]; [oStream open]; } { NSString *io; if (theStream == iStream) io = @">>"; else io = @"<<"; NSString *event; switch (streamEvent) { case NSStreamEventNone: event = @"NSStreamEventNone"; resultText.font = [UIFont fontWithName:@"Helvetica" size:10.0]; resultText.textColor = [UIColor whiteColor]; break; case NSStreamEventOpenCompleted: event = @"NSStreamEventOpenCompleted"; break; case NSStreamEventHasBytesAvailable: event = @"NSStreamEventHasBytesAvailable"; if (theStream == iStream) { uint8_t buffer[1024]; int len; while ([iStream hasBytesAvailable]) { if (len > 0) { if (nil != output) { //NSArray *arr = [output componentsSeparatedByString:@"\n"]; resultText.font = [UIFont fontWithName:@"Helvetica" size:10.0]; resultText.textColor = [UIColor whiteColor]; NSLog(@"%@", output); [output release]; } } } } break; case NSStreamEventHasSpaceAvailable: event = @"NSStreamEventHasSpaceAvailable"; break; case NSStreamEventErrorOccurred: event = @"NSStreamEventErrorOccurred"; resultText.font = [UIFont fontWithName:@"Helvetica" size:10.0]; resultText.textColor = [UIColor whiteColor]; break; case NSStreamEventEndEncountered: event = @"NSStreamEventEndEncountered"; [theStream close]; [theStream release]; theStream = nil; break; default: event = @"** Unknown"; } NSLog(@"%@ : %@", io, event); }
URL: http://www.iphonedevsdk.com/forum/iphone-sdk-development/2998-how-socket-connection.html