My application want to run one http server and other devises can download files from it.
I am using cocoa http server and follow: https://github.com/robbiehanson/CocoaHTTPServer/blob/master/Samples/DynamicServer/MyHTTPConnection.m
My http connection is:
@implementation MyHTTPConnection
- (NSObject<HTTPResponse> *)httpResponseForMethod:(NSString *)method URI:(NSString *)path
{
NSString *filePath = [self filePathForURI:path];
// Convert to relative path
NSString *documentRoot = [config documentRoot];
NSString *relativePath = [filePath substringFromIndex:[documentRoot length]];
NSLog(@"file path is %@", filePath);
//return [super httpResponseForMethod:method URI:path];
return [[HTTPFileResponse alloc] initWithFilePath:filePath forConnection:self];
}
@end
And the code in Delegate is :
httpServer = [[HTTPServer alloc] init];
[httpServer setConnectionClass:[MyHTTPConnection class]];
[httpServer setType:@"_http._tcp."];
NSString *webPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"web"];
if(webPath){
NSString * ip = '192.168.1.10';
int port = 3321;
[httpServer setDocumentRoot:webPath];
[httpServer setPort:port];
[httpServer setInterface: ip];
[self startServer];
}
When I download the test file in web document , the size is always o bytes.