Link to home
Start Free TrialLog in
Avatar of foysh
foysh

asked on

Can the server report to client about it`s progress of transferring a file ?

I need to be able to monitor the progress (and present it to the end-user)
of sending a file from Server to client as the client is unable to monitor the progress.
I`m using Wowza media server (rtmp protocol and java server side) and AS3 flash client.
The reason the AS3 client can`t monitor the progress is that
I suffer from FP-1959 Adobe known bug in a slightly different manner then described on the
adobe web page dedicated to it, here:
http://bugs.adobe.com/jira/browse/FP-1959

The AS3 clients connects to a java module on the server (with NetConnection) and asks
to send it a file. The java module sends the requested file as a bytearray.
The AS3 client recieves, BUT it can not present a progress bar of the transfer as
the AS3 Loader class is not accessible while the transfer lasts.
It becomes accessible only when the file is loaded, as described in the  FP-1959 Adobe known bug page.
I have tried transferring this file with amfphp server instead of the Wowza java rtmp server
but the AS3 client bug remains adamant : It can`t be done neither with listening to progressEvent nor with listening to ENTER_FRAME.

As a result of this obstacle I need a whole new way to monitor progress.
Any idea will be very welcome.
Even a general notion may help.
Perhaps there is a way for the server to monitor the progress of sending the file to the client.
perhaps the server can write the progress to some status file and then the client can read it.
perhaps this progress can be polled somehow.

I attached to this message the java server side script responsible for serving the requested file over rtmp.
Many thanks in advance for your efforts.


package com.wowza.wms.security;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

import com.wowza.wms.amf.*;
import com.wowza.wms.client.*;
import com.wowza.wms.module.*;
import com.wowza.wms.request.*;

public class ModuleSwfLoader extends ModuleBase {

	public void loadSwf(IClient client, RequestFunction function, AMFDataList params) {
		//getLogger().info("loadSwf");
		String swfName = "";
		byte[] fileBytes = null;
		
		if (getParam(params, PARAM1).getType() == AMFData.DATA_TYPE_STRING) {
			String contentFolder = client.getAppInstance().getStreamStoragePath() + File.separator;
			swfName  = contentFolder + params.getString(PARAM1);
			getLogger().info("swfLocation: " + swfName);
		}
		
		try {
			if (!swfName .isEmpty()) {
				File swf = new File(swfName);
				if (swf.exists() && swf.canRead() && swf.isFile() && swf.length() < Integer.MAX_VALUE) {
					InputStream in = new FileInputStream(swf);
						int length = (int) swf.length();
						fileBytes = new byte[length];

						int offset = 0;
				        int numRead = 0;
				        while (offset < fileBytes.length && (numRead=in.read(fileBytes, offset, fileBytes.length-offset)) >= 0) {
				            offset += numRead;
				        }
				        
				        if (offset < fileBytes.length) {
				            throw new IOException("Could not completely read file "+swf.getName());
				        }
				        
				        in.close();
				}
			}
		} catch (FileNotFoundException e) {
			getLogger().info("file not found");
			e.printStackTrace();
		} catch (IOException e) {
			getLogger().info("IOException");
			e.printStackTrace();
		}
		sendResult(client, params, AMFDataByteArray.wrap(fileBytes));
	}

}

Open in new window

Avatar of afumedo
afumedo


 Here is some steps you may do:

1- Ask the server for the size of the file: send a Request to the server giving it the ( File Name ) you need and a certain ( parameter ) , and the server should then pass the size of the file to its client.

# IF you can see the currently available bytes transfered to the client
    2- then you now should be able to display the progress ( received / total-size )

# ELSE
    2- select a chunk size ( say 4KB or whatever you see ) and tell the server to give you a portion of the file ( starting from byte X )  with length (chunk-size ) and so, when you receive that chunk you would be able to display a proper progress information.

Psudo code attached.

#ENDIF

Best wishes,

Regards,

Ahmed Bedier
class MyClass
{
    int chunkSize ; //in bytes
    int start = 0 ;
    int totalSize ;

    private void getSWFFile( fileName )
    {
         // send a request for the file size.
    }

    private void on_file_size_received()
    {
        // select a chunk size and request all file-chunks from server
       
        start = 0 
        chunkSize = 4096 ; 
          
        // request first chunk
        sendChunkRequest (start, chunkSize )
    }  

    private void sendChunkRequest ( start, ChunkSize )
    {
        // send request with proper parameters.
    }

    private void on_current_chunk_received()
    {
        // display progress
        int progress = (int)( 100 * ( received / total size ) ) ;

        // if (received != totalSize) 
        //    request the next chunk
        //else
        //    file download complete.
    }
}

Open in new window

Avatar of foysh

ASKER

Dear Ahmed Bedier.
First of all I`d like to heartily thank you for your reply as well as deeply apologise for the delay in my response. This Delay is partly due to my attempting to understand the implications of you suggestion.
I must say that if I only understand how to put your idea to actual code this would be a truely perfect solution for me.
For this reason I`d like to ask you whether you think this is possible to perform in AS3 for client side. I don`t really know any command in AS3 that asks for only a portion of a bytearray. Or if this is to be done withany other client sdie language, would you specify which, please ?
I`d also like to ask you whether in order to put your idea to action, I should change accordingly the server side Java script which I attached to my original message.

Many thanks for your attention and assistance !
Avatar of foysh

ASKER

As I could find no EDIT option on the board, I repost the 7th and 8th lines of my previuos message , that contained typo errors:
 
"really know any command in AS3 that asks for only a portion of a bytearray. Or if this is to be done with any other client side language, would you specify which, please ?"

Sorry and thanks.
ASKER CERTIFIED SOLUTION
Avatar of afumedo
afumedo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of foysh

ASKER

Thank you,
Ahmed Bedier, for your assistance, and thanks also for clarifying, your answer has helped me in understanding tha path I should take.
Avatar of foysh

ASKER

Many thanks.