NetTalk Central

Author Topic: NetSimpleClient - checking for connection closed  (Read 4018 times)

CyberFerret

  • Newbie
  • *
  • Posts: 32
    • View Profile
    • Email
NetSimpleClient - checking for connection closed
« on: December 11, 2008, 04:29:19 AM »
Hi all,

I am playing with the NetSimpleClient object to send GET and POST requests to Amazon.

The problem is, I cannot see any way to check if the server has finished sending me data back.  Is there a property somewhere that will tell me the server has done the job and is finished?

Data coming back can range from 100 bytes up to 10 megabytes (I am sending queries to Amazon S3).

I have tried putting code in the ConnectionClosed() point, but this never seems to be called?!?!

Thanks,
Devan

Rob Mikkelsen

  • Full Member
  • ***
  • Posts: 107
    • Yahoo Instant Messenger - flashpott
    • View Profile
    • Email
Re: NetSimpleClient - checking for connection closed
« Reply #1 on: December 11, 2008, 01:07:18 PM »
I believe that PageReceived event is only fired when the complete page is available.  You should be able to take this as a given that the whole page is available for review.

CyberFerret

  • Newbie
  • *
  • Posts: 32
    • View Profile
    • Email
Re: NetSimpleClient - checking for connection closed
« Reply #2 on: December 11, 2008, 08:40:55 PM »
Hi flashpot - thanks for the reply.

PageReceived() works beautifully in NetWebClient, however I am using NetSimpleClient, which is a lot more Spartan that the WebClient.

AFAIK - NetSimpleClient fires the Process() method each time a packet of data comes in, which is fine, however, I have no idea when the last packet is received, unless the connection eventually times out.  If there was some way to work out which packet finishes the stream then it would all be fine and dandy.  I thought that putting the cleanup code in ConnectionClosed() method would work, but it looks like the Amazon server uses persistent connections and keeps it open until I close it - which is difficult to do if I am not sure when to close it in the first place!! :)

This is regardless of whether I include the "Connection: close" header line when sending my request.

It looks like I will have to parse the returned header to find out the "Content-Length" property and check that against the data downloaded to see if I have got it all.  What makes this harder is that Amazon returns some requests as "chunked" data which means I have to wait until it sends me a zero size chunk command, which can be in the middle of the second last packet....aaaargh!

Making this even harder is that there is no way to separate the returned header from the data in NetSimpleClient.  I will have to manually parse the first packet to split the header out and identify each line.

I wonder how hard it would be to hack the code and try to inherit some of the NetWebClient methods into my NetSimpleClient object?!?!?!?! :)

Cheers,
Devan