Want more features on Pastebin? Sign Up, it's FREE!
Guest

SSL -9800 Error

By: a guest on Jul 26th, 2012  |  syntax: Objective C  |  size: 2.97 KB  |  views: 103  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. - (BOOL)setupSocketStreams {
  2.  
  3.     // Make sure streams were created correctly
  4.     if ( readStream == nil || writeStream == nil ) {
  5.         [self close];
  6.         return NO;
  7.     }
  8.  
  9.     // Create buffers
  10.     incomingDataBuffer = [[NSMutableData alloc] init];
  11.     outgoingDataBuffer = [[NSMutableData alloc] init];
  12.  
  13.     // Indicate that we want socket to be closed whenever streams are closed
  14.     CFReadStreamSetProperty(
  15.             readStream,
  16.             kCFStreamPropertyShouldCloseNativeSocket,
  17.             kCFBooleanTrue
  18.     );
  19.     CFWriteStreamSetProperty(
  20.             writeStream,
  21.             kCFStreamPropertyShouldCloseNativeSocket,
  22.             kCFBooleanTrue
  23.     );
  24.  
  25.  
  26.     const void* values[] = { CFSTR("kCFStreamSocketSecurityLevelTLSv1_0SSLv3") };
  27.     const void* keys[] = { kCFStreamSSLLevel };
  28.  
  29.     CFDictionaryRef sslSettingsDict = CFDictionaryCreate(kCFAllocatorDefault, keys, values, 1,
  30.             &kCFTypeDictionaryKeyCallBacks,
  31.             &kCFTypeDictionaryValueCallBacks);
  32.  
  33.     CFReadStreamSetProperty(
  34.             readStream,
  35.             kCFStreamPropertySSLSettings,
  36.             sslSettingsDict
  37.     );
  38.  
  39.     CFWriteStreamSetProperty(writeStream,
  40.             kCFStreamPropertySSLSettings,
  41.             sslSettingsDict
  42.     );
  43.  
  44.     CFRelease(sslSettingsDict);
  45.  
  46.  
  47.  
  48.     // We will be handling the following stream events
  49.     CFOptionFlags registeredEvents =
  50.             kCFStreamEventOpenCompleted     |
  51.                     kCFStreamEventHasBytesAvailable |
  52.                     kCFStreamEventCanAcceptBytes    |
  53.                     kCFStreamEventEndEncountered    |
  54.                     kCFStreamEventErrorOccurred
  55.     ;
  56.  
  57.     // Setup stream context - reference to 'self' will be passed to stream event handling callbacks
  58.     CFStreamClientContext ctx = {
  59.             0,      // version
  60.             self,   // info
  61.             NULL,   // retain callback
  62.             NULL,   // release callback
  63.             NULL    // copyDescription callback
  64.     };
  65.  
  66.     // Specify callbacks that will be handling stream events
  67.     CFReadStreamSetClient(
  68.             readStream,
  69.             registeredEvents,
  70.             readStreamEventHandler,
  71.             &ctx
  72.     );
  73.     CFWriteStreamSetClient(
  74.             writeStream,
  75.             registeredEvents,
  76.             writeStreamEventHandler,
  77.             &ctx
  78.     );
  79.  
  80.     // Schedule streams with current run loop
  81.     CFReadStreamScheduleWithRunLoop(
  82.             readStream,
  83.             CFRunLoopGetCurrent(),
  84.             kCFRunLoopCommonModes
  85.     );
  86.     CFWriteStreamScheduleWithRunLoop(
  87.             writeStream,
  88.             CFRunLoopGetCurrent(),
  89.             kCFRunLoopCommonModes
  90.     );
  91.  
  92.     // Open both streams
  93.     if ( ! CFReadStreamOpen(readStream) || ! CFWriteStreamOpen(writeStream)) {
  94.         [self close];
  95.         return NO;
  96.     }
  97.  
  98.     if ([self.delegate respondsToSelector:@selector(establishedConnection:)]) {
  99.         [self.delegate establishedConnection:self];
  100.     }
  101.  
  102.     return YES;
  103. }
clone this paste RAW Paste Data