• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
HTTP server with NetSocket
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

HTTP server with NetSocket


  • Subject: HTTP server with NetSocket
  • From: Pierre Chatel <email@hidden>
  • Date: Wed, 18 May 2005 12:37:03 -0300

Hi !

following my post asking for a lightweight embeddable http server, thanks for all the answer btw :-), i decided to implement it myself using NetSocket.
It's working pretty well for the rss/xml part, but i need to make file transfers with the http/1.0 protocol. It's working for very small files. But all others are truncated. The biggest chunk of data i managed to download was 60~80Kb. So maybe i'm missing something with netsocket or with the http protocol.
Here is an extract of the code i'm using to respond to the GET method for a file:

//data output the http header and, eventually, the xml file
[inNetSocket writeData:[aResponse data]];
//if it's a file transfer we add the file's data directly after the header
if([[response contentType] isEqualToString:@"application/x-zip"]) {
     [inNetSocket writeData:[response attachementData]];
}


(...)

-(NSData* )data {
    NSMutableString* aString = [[NSMutableString alloc] initWithCapacity:1024];
    [aString autorelease];
    // add HTTP status line
    [aString appendFormat:@"%@ d %@\x0D\x0A",@"HTTP/1.0",[self status],[self statusCode]];
    [aString appendFormat:@"Content-Type: %@\x0D\x0A",[self contentType]];
    if([[self contentType] isEqualToString:@"application/x-zip"]) {
        [aString appendFormat:@"Content-Length: %d\x0D\x0A",[_attachement length]];
        [aString appendString:@"\x0D\x0A"];
    }
    else {
        [aString appendString:@"\x0D\x0A"];
        [aString appendString:[self content]];
    }
    return [aString dataUsingEncoding:NSUTF8StringEncoding];
}

-(NSData* )attachementData {
    return _attachement;
}


So, as you can see, i even put the content-length optional attribute !
Is it that i can't directly write big data chunck to a netsocket ? Do i have to split it ? Should i respond to other type of http requests ?

Pierre 

Attachment: smime.p7s
Description: S/MIME cryptographic signature

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: HTTP server with NetSocket
      • From: Cameron Hayne <email@hidden>
  • Prev by Date: Pie shapes
  • Next by Date: Re: Can NSCell draw both an icon and text?
  • Previous by thread: Re: Pie shapes
  • Next by thread: Re: HTTP server with NetSocket
  • Index(es):
    • Date
    • Thread