Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting no client connected after downloading some part #6

Open
rohitgarg29 opened this issue Feb 13, 2019 · 10 comments
Open

Getting no client connected after downloading some part #6

rohitgarg29 opened this issue Feb 13, 2019 · 10 comments

Comments

@rohitgarg29
Copy link

Hi @chandilsachin

I am getting following error after downloading some part of the file. please help me if you know the reason. thanks in advance :)

LocalFileStreamingServer: No client connected, waiting for client...
java.net.SocketTimeoutException: Poll timed out
at libcore.io.IoBridge.poll(IoBridge.java:691)
at java.net.PlainSocketImpl.socketAccept(PlainSocketImpl.java:183)
at java.net.AbstractPlainSocketImpl.accept(AbstractPlainSocketImpl.java:416)
at java.net.ServerSocket.implAccept(ServerSocket.java:547)
at java.net.ServerSocket.accept(ServerSocket.java:515)
at com.dewa.dewadrive.controller.LocalFileStreamingServer.run(LocalFileStreamingServer.java:145)
at java.lang.Thread.run(Thread.java:764)

Regards,
Rohit

@chandilsachin
Copy link
Owner

chandilsachin commented Feb 13, 2019 via email

@rohitgarg29
Copy link
Author

@chandilsachin i am using the same code only from your other repository, problem is that
1.) file downloads (lets say 10mb) and does not play
2.) then if i start again, it downloads more as compare to previous one (lets say 30mb) and stops at some point

i implemented using BaseHttpResponse not using HttpUrlCOnnection because i have to authenticate the url before downloading as sample is not able with HttpUrlConnection.

@rohitgarg29
Copy link
Author

@chandilsachin any update on this please?

@chandilsachin
Copy link
Owner

chandilsachin commented Feb 18, 2019 via email

@rohitgarg29
Copy link
Author

@chandilsachin

Only file changed is :

public class VideoDownloader extends AsyncTask<String, Integer, Void>
{
public static final int DATA_READY = 1;
public static final int DATA_NOT_READY = 2;
public static final int DATA_CONSUMED = 3;
public static final int DATA_NOT_AVAILABLE = 4;
private Context context;

public static int dataStatus = -1;

public VideoDownloader(Context context) {
    this.context = context;
    readb = 0;
}

public static boolean isDataReady(){
    dataStatus = -1;
    boolean res = false;
    if(fileLength == readb){
        dataStatus = DATA_CONSUMED;
        res = false;
    }else if(readb > consumedb){
        dataStatus = DATA_READY;
        res = true;
    }else if(readb <= consumedb){
        dataStatus = DATA_NOT_READY;
        res = false;
    }else if(fileLength == -1){
        dataStatus = DATA_NOT_AVAILABLE;
        res = false;
    }
    return res;
}

/**
 * Keeps track of read bytes while serving to video player client from server
 */
public static int consumedb = 0;

/**
 * Keeps track of all bytes read on each while iteration
 */
private static int readb = 0;

/**
 * Length of file being downloaded.
 */
static int fileLength = -1;

@Override
protected Void doInBackground(String... params)
{

    HttpClient httpClient = ConnectionUtils.getAuthenticatedHttpClient(context);
    InputStream is = null;
    FileOutputStream fos = null;

    try {
        //forming a HttpGet request


        final HttpGet getRequest = new HttpGet(params[0]);
        BasicHttpResponse httpResponse = (BasicHttpResponse) httpClient.execute(getRequest);
        if (httpResponse.getStatusLine().toString().equalsIgnoreCase("HTTP/1.1 401 Unauthorized")) {
            return null;
        }

// fileLength = httpResponse.getEntity().getContent().toString().length();
is = httpResponse.getEntity().getContent();
fos = new FileOutputStream(params[1]);
int read = 0;
long readBytes = 0;
byte[] buffer = new byte[32768];
while ((read = is.read(buffer)) > 0) {
fos.write(buffer, 0, read);
fos.flush();
readBytes += read;
readb += read;
// Log.w("download", (readb / 1024) + "kb of " + (fileLength / 1024) + "kb");
}
FileUtils.safeClose(fos);
FileUtils.safeClose(is);
} catch (ClientProtocolException e) {
// AppLog.getInstance().logError(TAG, "ClientProtocolException:- " + e.getMessage());
return null;
} catch (IOException e) {
// AppLog.getInstance().logError(TAG, "IOException:- " + e.getMessage());
return null;
} catch (Exception e) {
// AppLog.getInstance().logError(TAG, "Exception:- " + e.getMessage());
return null;
} finally {
FileUtils.safeClose(fos);
FileUtils.safeClose(is);
}

   /* BufferedInputStream input = null;
    try
    {
        final FileOutputStream out = new FileOutputStream(params[1]);

        try
        {
            URL url = new URL(params[0]);

            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.connect();
            if (connection.getResponseCode() != HttpURLConnection.HTTP_OK)
            {
                throw new RuntimeException("response is not http_ok");
            }
            fileLength = connection.getContentLength();

            input = new BufferedInputStream(connection.getInputStream());
            byte data[] = new byte[1024 * 50];
            long readBytes = 0;
            int len;
            boolean flag = true;

            while ((len = input.read(data)) != -1)
            {
                out.write(data, 0, len);
                out.flush();
                readBytes += len;
                readb += len;
                Log.w("download", (readb / 1024) + "kb of " + (fileLength / 1024) + "kb");
            }
        } catch (MalformedURLException e)
        {
            e.printStackTrace();
        } catch (IOException e)
        {
            e.printStackTrace();
        } finally
        {
            if (out != null)
            {
                out.flush();
                out.close();
            }
            if (input != null)
                input.close();
        }
    } catch (IOException e)
    {
        e.printStackTrace();
    }*/
    return null;
}

@Override
protected void onPostExecute(Void aVoid)
{
    super.onPostExecute(aVoid);
    Log.w("download", "Done");
}

// public String downloadByteFile(String urlString) {
//
// return SUCCESS;
// }
}

But it throws exception at File not found for first time and then the above exception but second time, it is working fine. l

@rohitgarg29
Copy link
Author

hi @chandilsachin can you please help me with this one?

@chandilsachin
Copy link
Owner

chandilsachin commented Feb 25, 2019 via email

@rohitgarg29
Copy link
Author

Hi @chandilsachin I want to check with you regarding the buffer size. DO i need to increase buffer size for more than 50 mb videos?

@chandilsachin
Copy link
Owner

chandilsachin commented Apr 7, 2019 via email

@rohitgarg29
Copy link
Author

I am not sure whats causing the issue for 200 mb video files. I will check, if you get time, can you please try as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants