Please help me w/ this code

I have an idea for a ruby software that I want to submit to rubyforge. The
only problem is I am stuck trying to figure out a small problem. I am
writing a file server that sends a file via sockets, and the client simply
downloads a file from the server.

Using ‘progressbar’ from RAA, I want a meter bar that tells the client how
much of the file is being downloaded.

Here is the server code

···

require “socket"
gs = TCPserver.new(‘localhost’, 80)
loop do
s = gs.accept
Thread.new(s) do |sock|
print(sock, " is accepted\n”)
sock.write(File.read(“asp.txt”))
sock.close
end
end

Here is the client code
require "socket"
TCPsocket.open(‘localhost’, 80) do |s|
File.open(“output.exe”, “wb”) { |f| f.write s.read }
end

And this is a sample code off of the progress from RAA
require ‘progressbar’

total = 1000
pbar = ProgressBar.new(“test(inc)”, total)
total.times {
sleep(0.02)
pbar.inc
}
pbar.finish


Basically I need to combine the progressbar example into the client code. So
the client can read a meter instead of just waiting, not knowing how much of
the file is being downloaded. I am quit new to Ruby and I am asking for some
assistance for this implementation or modified code.

Thank you

Daniel wrote:

Basically I need to combine the progressbar example into the client code. So
the client can read a meter instead of just waiting, not knowing how much of
the file is being downloaded. I am quit new to Ruby and I am asking for some
assistance for this implementation or modified code.

This doesn’t work, to show a progress bar you need to know how much will
be transmitted in total. Then it is very easy: in a loop you read only
filesize/100 bytes at a time and update the progress bar.

···


http://www.mikrocontroller.net - Das Mikrocontroller-Forum