NetTalk Central

Author Topic: netwebclient and progress ?  (Read 4221 times)

dave beggs

  • Newbie
  • *
  • Posts: 1
    • View Profile
netwebclient and progress ?
« on: December 29, 2013, 09:58:32 PM »
Hi
Is there a way to track progress with a NetWebClient when posting to a SOAP server?
there doesn't seem to be a calcprogress() method ...
Cheers
Dave Beggs

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11176
    • View Profile
Re: netwebclient and progress ?
« Reply #1 on: January 01, 2014, 11:39:59 PM »
Morning Dave,

I'm guessing what you have is a large POST command, and a "slow" connection, such that it "takes time" for the POST to be completely sent to the server. In order to calculate progress though, it's useful to understand the path the POST will take through your program.

a) The WebClient class will build the POST request, break it up into "packets" and send it from your program thread to the networking thread. This stage is all "in memory" in the calling procedure, and typically happens quite quickly.

b) the NetWork thread then sends the packets out to the WinSock driver. again this happens quite fast.

c) The Winsock driver then sends the packets to the receiver at the speed that the connection allows. This could take minutes for a big file.

d) The server sends back a response. The response might be small, or large. The response arrives as packets, which are fed into the .Process method. Once all the packets have arrived, the .PageReceived methd is called.

So a typical workflow with the web client is to call FETCH or POST, and then put the "what to do when it's finished code" in .PageReceived.

I'm assuming you want to track progress of the c) or d) steps? d) is the easier one (by far);

In the .Process method, the incoming expected length is set in the self._PageContentLen property. Once this is set (bearing in mind that it starts out at zero until the content-length header has been parsed) you can also check self.PageLen to see how much of the page has been received.

So calculating the progress of the incoming page becomes (in .Process method, after the parent call)
If self._PageContentLen
  progress = (self._PageContentLen / self.PageLen) * 100
End


Update: In build 7.32 I've added a property self.Progress which is primed with the above calculation. Note that it will only work if the server sets the content-length header (something most servers do, but which isn't actually required for them to do.)

Calculating progress in the (c) case is much harder because (as far as I'm aware) there's no way to query the winsock layer  to see what's actually happening with regard to one specific POST.

cheers
Bruce
« Last Edit: January 01, 2014, 11:46:16 PM by Bruce »