• 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
Re: Write stream proxy
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Write stream proxy


  • Subject: Re: Write stream proxy
  • From: Mark Pauley <email@hidden>
  • Date: Thu, 11 Sep 2008 15:00:47 -0700

So, a fundamental question - the docs tell me that I need to use a write
stream to send the data (2KB at a time) to the server. Is this true, or
should I be looking at readstreams for the file transfer? It seems strange
to use a read stream to write data...
Hence the CFStreamCreateBoundPair. It makes a stream hose with a writestream (which you use to write the data) which we'll read from the readstream when we are about to transmit data. This way we can buffer a minimum and we get a nice asynchronous model of piping data from the client onto the wire.

What I would really like is a http call set that takes care of the proxy for
us, any chance? Networking code used to be rather easy, just open a socket,
bind it, then start sending data. Looks like I've been away from it too
long.
We currently have no method of wrapping a socket stream with an http stream. I'm not sure we could really guarantee this would work anyhow. For now, use the CFReadStreamCreateForStreamedHTTPRequest API... and make sure to use the Content-Length header because a surprising amount of http servers don't support chunked uploads (which we'll fall back to in the case that you don't set the Content-Length header).



On 9/10/08 5:18 AM, "Quinn" <email@hidden> wrote:

At 10:26 -0700 9/9/08, Jack Brindle wrote:
For file transfers we do the same thing except create the dual
socket setup and call CFReadStreamCreateForStreamedHTTPRequest on
the read stream. However the read stream looks to be handled as a
raw stream of bits, without http-specific handling. It uses
CFWriteStreamWrite to send the data. No calls are made to anything
with the characters HTTP in the name for this stream. Am I right in
the feeling that this really isn't what I need to have?

It depends (-: When you create a streamed CFHTTP request (by calling CFReadStreamCreateForStreamedHTTPRequest) CFHTTP will call the supplied read stream to get the bytes for the body of the request. This isn't HTTP at all, it's just a raw stream of bytes. A typical usage is, if you want to upload a file, you create a file read stream (CFReadStreamCreateWithFile) and pass that to CFReadStreamCreateForStreamedHTTPRequest.

The only reason you need to do the whole socket pair thing is if the
data that you want to upload isn't present in one single file (or one
single block of memory).  In that case, you have a number of options:

A. If the data is relatively small, you can flatten it to a temporary
file and then create a file read stream and use that.  Similarly, you
can flatten it to a temporary block of memory.

OTOH, if the data is large, this approach is too inefficient.

B. If you're OK with using Objective-C and the data is all present
(that is, you don't need to be scheduled on a runloop in order to
produce the data), you can create the data from a custom subclass of
NSInputStream.  Subclassing NSInputStream for asynchronous streams
isn't something we support, but it should be OK for synchronous
streams.

I haven't actually tried this though (-:

C. If all else fails, you can produce the data using the technique
that you're already using, that is, create a socket pair, create a
read stream for one member of the pair and a write stream for the
other, and feed the data to the CFHTTP request by writing it to the
write stream.

If you do this you won't need to mess with proxies on the streams you
create for the socket pair.  Those streams are just used for internal
communication within your program.  The only stream that needs to
deal with proxies is the main CFHTTP stream.

S+E

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

_Mark email@hidden




_______________________________________________ Do not post admin requests to the list. They will be ignored. Macnetworkprog mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >Re: Write stream proxy (From: Jack Brindle <email@hidden>)

  • Prev by Date: Re: Write stream proxy
  • Next by Date: Re: Write stream proxy
  • Previous by thread: Re: Write stream proxy
  • Next by thread: Re: Write stream proxy
  • Index(es):
    • Date
    • Thread