Solved!
On Sunday, 22 June 2014 18:58:20 UTC+1, Simon Platten wrote:
>
> I've been working on a Java application for a while now, on my development
> system it runs fine and works as I would expect. However when testing on
> the Beaglebone black it doesn't work as expected.
>
> The application is a web-server that serves up a specific set of pages,
> (index.html, a css and javascript file and some images).
>
> When run from my development PC, it returns the documents correctly, on
> the beaglebone black it doesn't return, until I terminate the application.
>
> Below is my function to send back a response:
> [code]
> /**
> * Method:
> * httpResponse
> * @param dos, the data output stream to send back the response to
> * @param arybytResponse, a byte array containing the response
> * @param strMIME, optional mimic type
> */
> public static void httpResponse(DataOutputStream dos,
> byte[] arybytResponse,
> String strMIME) {
> try {
> final String CRLF = "\r\n";
>
> File objFile = null;
> String strResponse =
> HTTP_ID + "/1.1 200 OK" + CRLF +
> "Cache-Control: no-cache, must-revalidate" + CRLF +
> "Expires: Mon, 26 Jul 1997 05:00:00 GMT" + CRLF +
> "Content-type: ";
> if ( strMIME != null ) {
> strResponse += strMIME;
> } else {
> strResponse += mstrMIME;
> }
> strResponse += CRLF;
>
> if ( mstrError != "" ) {
> //Publish the error message
> strResponse += CRLF + "{\"error\":\"" + mstrError +
> "\"}";
> dos.write(strResponse.getBytes());
> dos.write(arybytResponse);
> dos.close();
> return;
> }
> if ( mblnBinary == true ) {
> strResponse += CRLF;
> dos.write(strResponse.getBytes());
> dos.write(arybytResponse);
> dos.close();
> return;
> }
> String strJSON = new String(arybytResponse);
>
> if ( strJSON.endsWith(".html") == true ) {
> //strJSON contains a html document reference
> String strPath = mstrAppPath + strJSON;
> objFile = new File(strPath);
> } else {
> //Default to JSON content
> strResponse += "Content-length: " +
> Integer.toString(strJSON.length()) + CRLF + CRLF
> +
> strJSON;
> }
> if ( objFile != null ) {
> if ( objFile.exists() == false ) {
> String strNotFound = "<html><body>Not
> found!</body></html>";
> strResponse += "Content-length: " +
> Integer.toString(strNotFound.length()) +
> CRLF + CRLF +
> strNotFound;
> } else {
> InputStream is = new FileInputStream(objFile);
> byte[] arybytFile = new byte[(int)objFile.length()];
> is.read(arybytFile);
> is.close();
> strResponse += "Content-length: " +
> Integer.toString(arybytFile.length)
> + CRLF + CRLF +
> new String(arybytFile);
> }
> }
> dos.write(strResponse.getBytes());
> dos.close();
> } catch (IOException ex) {
> //Not interested in errors here
> //ex.printStackTrace();
> }
> }
> [/code]
>
> Thank you for any help.
>
--
For more options, visit http://beagleboard.org/discuss
---
You received this message because you are subscribed to the Google Groups
"BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.