Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add run-time information to CocoaHTTPServer using custom Response class #5

Closed
besi opened this issue Jan 26, 2012 · 2 comments
Closed

Comments

@besi
Copy link

besi commented Jan 26, 2012

I have the following code to start my own Cocoa HTTP Server. In order to manually handle the responses I have created my custom HTTPConnection class named PictureHTTPConnection

self.httpServer = [[HTTPServer alloc]init];
self.httpServer.type = @"_http._tcp.";
self.httpServer.name = @"MyBonjour Name";
self.httpServer.connectionClass = [PictureHTTPConnection class];

The problem here is that the PictureHTTPConnection class needs some information in order to handle the HTTP connections. However, I only provide the class and therefore I don't have a reference to the instance. I could do something with global data but this is not very good programming practise.

The best way I can think of is setting the PictureHTTPConnection's delegate to the UIApplicationDelegate so that it can answer any callbacks. :-(

@robbiehanson
Copy link
Owner

When a new connection is accepted from the HTTPServer, it creates a new instance of PictureHTTPConnection. In other words, it does this:

newConnection = [[PictureHTTPConnection alloc] initWithAsyncSocket:newSocket configuration:[self config]];

You have a reference to the instance within the PictureHTTPConnection class (via self).

@zakdances
Copy link

Why aren't HTTPConnection classes instantiated with a delegate method instead of just handing over the class to httpServer .connectionClass? That way we'd be able to assign to assign a delegate to HTTPConnection and move logic to a controller of our choice instead of having no way to reference anything except self...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants