Ver código fonte

Set the HTTP listening port to 8888

If it fails, take a random one
Jean-Baptiste Kempf 12 anos atrás
pai
commit
06d1cdf54f
1 arquivos alterados com 11 adições e 2 exclusões
  1. 11 2
      AspenProject/VLCHTTPUploaderController.m

+ 11 - 2
AspenProject/VLCHTTPUploaderController.m

@@ -36,7 +36,7 @@ static const int httpLogLevel = HTTP_LOG_LEVEL_VERBOSE; // | HTTP_LOG_FLAG_TRACE
 -(BOOL)changeHTTPServerState:(BOOL)state
 {
     if(state) {
-        // To keep things simple and fast, we're just going to log to the Xcode console.
+        // Just log to the Xcode console.
         [DDLog addLogger:[DDTTYLogger sharedInstance]];
 
         // Initalize our http server
@@ -52,12 +52,21 @@ static const int httpLogLevel = HTTP_LOG_LEVEL_VERBOSE; // | HTTP_LOG_FLAG_TRACE
         DDLogInfo(@"Setting document root: %@", docRoot);
 
         [self.httpServer setDocumentRoot:docRoot];
-
+        
+        [self.httpServer setPort:8888];
+         
         [self.httpServer setConnectionClass:[VLCHTTPConnection class]];
 
         NSError *error = nil;
         if(![self.httpServer start:&error])
         {
+            /* Address already in Use, take a random one */
+            if(error.code == 48) {
+                DDLogError(@"Address already in use, trying another one");
+                [self.httpServer setPort:0];
+                if([self.httpServer start:&error])
+                    return true;
+            }
             DDLogError(@"Error starting HTTP Server: %@", error);
             return false;
         }