Stopping and starting server causes multiple startup messages

27 views
Skip to first unread message

Mark

unread,
Dec 27, 2011, 1:31:03 PM12/27/11
to CocoaHTTPServer
I'm using cocoahttpserver in an iOS app I'm building and was seeing
the following behavior. In the app, I allow the user to stop and start
the server. When I stop the server and then start it again, I get
multiple messages regarding the server starting. This is a multiple of
the times it's been started. For instance:

1. Webserver starts during app didFinishLaunchingWithOptions.
Response:" HTTPServer: Started HTTP server on port 58781" (I have
the port hardcoded for the moment)
2. Stop the web server through the UI.
3. Start the web server through the UI.
REsponse: 2X "HTTPServer: Started HTTP server on port 58781"

Etc. For every start and stop, the total number of times this happens
goes up by one.

To be clear, everything *seems* to be working fine. The server stops
and starts but it's odd.

To make sure it wasn't something I did (I'm relatively new to this), I
copied the SimpleHTTPServer example project. I added two buttons,
"stop" and "start" and wired it up to the two methods below. Running
it on my mac, I'm seeing the same behavior. Any ideas why this would
be happening? Do I need to be concerned? I'm running iOS 5, Lion, and
Xcode 4.2.1.

Thanks.

====start code====
-(void) startWebServer: (id)sender {
[DDLog addLogger:[DDTTYLogger sharedInstance]];
httpServer = [[HTTPServer alloc] init];
[httpServer setType:@"_http._tcp."];

// Serve files from the standard Sites folder
NSString *docRoot = [@"~/Sites" stringByExpandingTildeInPath];
DDLogInfo(@"Setting document root: %@", docRoot);
[httpServer setDocumentRoot:docRoot];

NSError *error = nil;
if(![httpServer start:&error])
{
DDLogError(@"Error starting HTTP Server: %@", error);
}

}

-(void) stopWebServer: (id) sender {
[httpServer stop];
}
Reply all
Reply to author
Forward
0 new messages