kernelzack has asked for the wisdom of the Perl Monks concerning the following question:

Hello all,

I am trying to determine if the folloing is possible

I have written a client server program using IO::Socket. Basically I've embedded the client into a web page which talks to the server and returns results. Here is what I am trying to accomplish. The web client talks to the server and requests a file that resides on the server(not the web server, but the server that client embedded in the browser is talking to).How can I stream the data from the server to the users web browser? I know I can send the file from the server to the web server and than have the user download the file, but I am trying to avoid the middleman (the web server). Is there anyway to stream data from a remote machine to a users web browser? If you need me to elaborate please let me know.

Thank you for your time.
  • Comment on Download File From Remote machine to browser

Replies are listed 'Best First'.
Re: Download File From Remote machine to browser
by bart (Canon) on Apr 22, 2011 at 12:25 UTC
    How are you getting the file from the remote server to your web server anyway?

    If you're getting it through a handle (file handle, socket), then you simply need to have a script on your web server that sends out the appropriate content type in a header to the browser, and then passes on the chunks from the file while you're reading them from the remote server.

      Thanks very much for all these suggestions. I am going to try go the route bart mentioned and if that fails I will embed a web server/ftp server onto the 2nd server. To answer Believer's question, I just wanted to increase the speed of file transfer. Thank you all for your time, it's appreciated.
Re: Download File From Remote machine to browser
by Anonymous Monk on Apr 22, 2011 at 05:18 UTC
    How can I stream the data from the server to the users web browser? I know I can send the file from the server to the web server and than have the user download the file, but I am trying to avoid the middleman (the web server). Is there anyway to stream data from a remote machine to a users web browser? If you need me to elaborate please let me know.

    Exactly the same way, read data from one socket, write data to another socket.

    That is called a HTTP proxy , and it also has RFC(s)

Re: Download File From Remote machine to browser
by BrowserUk (Patriarch) on Apr 22, 2011 at 13:14 UTC

    It depends upon the protocol being used by the serving server?

    If it is a protocol the browser understands--http, ftp etc--then you can send a redirect to the browser and have it contact the remote server directly.

    With ftp, it is possible for a third party (client) to initiate a direct (PASV) transfer between two ftp servers. I'm not sure if it is possible for the third party client to initiate a PASV treansfer from a server to another client?


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re: Download File From Remote machine to browser
by believer (Sexton) on Apr 22, 2011 at 08:45 UTC
    Why do you want to avoid the middleman?
    And if you have a good reason for that, why not run a webserver on the second server?