<%@ page import = "com.cyscape.browserhawk.*" %>

<%
   // This sample is provided under the terms of the BrowserHawk End User License Agreement.
   // Copyright (c) 2003-2011 cyScape, Inc. All rights reserved.

   // This example demonstrates how to use BrowserHawk to detect the user's
   // UPLOAD connection speed throughput in bits per second and UPLOAD
   // connection latency in milliseconds.

   // Note: Use of the UploadConnectionSpeed or UploadConnectionLatency
   // checks can use a lot of bandwidth on the site to which the randomly
   // generated data used by these tests is transferred for timing purposes
   // (defaults to the server where the BrowserHawk test is running from).
   // This could cause a significant increase in your fees, depending on
   // your service plan with such providers and how traffic/bandwidth is
   // billed.  cyScape is not responsible for any such fees you may incur.
   // See the BH documentation for more information on how bandwidth is
   // used.

   // Display a friendly error message if the edition of BrowserHawk being
   // used is not sufficient to run this sample.  You should not include
   // this check in your BrowserHawk code.
   if (BrowserHawk.getVersion().indexOf("Pro") == -1 &&
       BrowserHawk.getVersion().indexOf("Ent") == -1) {
     out.println("Professional or Enterprise License Required.  ");
     out.println("You are using " + BrowserHawk.getVersion() + ".  ");
     out.println("See <a href='http://www.cyscape.com/order/'>http://www.cyscape.com/order/</a> for upgrade information.");
     return;
   }

   ExtendedOptions options = new ExtendedOptions();
   options.setPageTitle("Please wait...");
   options.setPageMessage("Please wait while your upload connection speed is detected...");
   options.addProperties("UploadConnectionSpeed, UploadConnectionLatency");
    
   ExtendedBrowserInfo extBrow = BrowserHawk.getExtendedBrowserInfo(request, response, options);
   if (extBrow == null) return;
%>

<html>
  <head>
    <title>BrowserHawk Sample - Upload Connection Speed Test (C#)</title>
  </head>
  <body><font face="arial">
  <blockquote>
    Your upload connection speed is: <%= extBrow.getUploadConnectionSpeed() %> <P>
    Your upload connection latency is: <%= extBrow.getUploadConnectionLatency() %> <P>

    Upload connection speed for display purposes: 
    <%=
      // The translate() method is a convenient way to display the speed in Mbps
      // and Kbps (dialup users) to end users, so we demonstrate that here.
      extBrow.translate("UploadConnectionSpeed")
    %> <P>

<%

// Although this script does not demonstrate it, below is an example of how you would get the
// result and do something with it.  For example, assume you wanted to handle things
// different for users with slow upload speeds.
// To get the speed in bits per second just check the uploadconnectionspeed property
// like this:
//    int uploadspeed = extBrow.getUploadConnectionSpeed();
// If you want to To calculate kbytes per second use this formula:
//    kbytesPerSec = uploadspeed / 8 / 1024;

// If you wanted to redirect users with slow connections here's how you can do it - in this
// example we redirect anyone with an upload speed slower than 768 kbits per second to a
// different page:
// if (uploadspeed > 0 && uploadspeed < 768000) {
//    response.sendRedirect("/basicpage.jsp");
// else if (speed < 1)
//    response.sendRedirect("/detection_na.jsp"); // timeout returns -1
// else
//    response.sendRedirect("/highspeed.asp");
// }
%>
<p>
<%
  if (extBrow.getUploadConnectionSpeed() >= 100000000) {
%>
    <b>Why is this speed so high</b> in this case? The upload speed check by
    default tests the speed to the server issuing the test, not the SupportFilesRoot
    location. When you're trying this on a local server, the speed will likely be very
    high. When this test is performed over the internet, you will see the expected results.
    <P>
<%
  }
%>
Also see the <a href="speed.jsp">download connection speed sample</a>
and the <a href="broadband.jsp">broadband sample</a>.
<P>
<HR>
<P>
<b><a href="uploadspeed.jsp">Retry this test</a></b><P>
<b><a href="index.html">Return to list of other JSP samples</a></b><P>
<b><a href="http://www.cyscape.com/order/">BrowserHawk Pricing and Ordering</a></b><P>
<b><a href="http://www.cyscape.com/">cyScape home page</a></b><P>
</font></blockquote>
</body>
</html>
