1 Reply Latest reply on May 5, 2015 11:52 AM by goodnewsjim

    App for medical emergency charity. Anyone have a Java echo server?

    goodnewsjim Level 1

      Hello,

       

      I found several Java socket echo servers that work well with Flash.

      The problem is that when I get the <policy-file-request>, I don't know how to handle it to make Flash happy.

       

      Does anyone have a bare bones Java echo server that can serve a cross domain policy file.

       

      All I want to do is get "Hello World" working, and I'll be able to finish an app I'm doing pro bono for a non profit regarding medical emergencies.

      I expected Cirrus to work on Android, but it didn't for me, so now I'm trying to do client<>server.  I am pretty sure client<>server will work, but I've been fighting with the cross domain policy request for 3-4 years now with no success.

       

      ,James

        • 1. Re: App for medical emergency charity. Anyone have a Java echo server?
          goodnewsjim Level 1

          Solution from Stackoverflow.com

           

          package server; 

          import java.io.BufferedReader; 

          import java.io.IOException; 

          import java.io.InputStreamReader; 

          import java.net.ServerSocket; 

          import java.net.Socket; 

          public class PolicyServer { 

          public static final String POLICY_XML =

                  "<?xml version=\"1.0\"?>"

                          + "<cross-domain-policy>"

                          + "<allow-access-from domain=\"*\" to-ports=\"*\" />"

                          + "</cross-domain-policy>\n";

           

           

           

          public PolicyServer(){

              ServerSocket ss = null;

              try {

                  ss = new ServerSocket(843);

              } catch (IOException e) {e.printStackTrace();}

              while(true){

                  try {

                      final Socket client = ss.accept();

                      new Thread(new Runnable() {

                          @Override

                          public void run() {

                              try {

                                  client.setSoTimeout(10000); //clean failed connections

                                  client.getOutputStream().write(PolicyServer.POLICY_XML.getBytes());

                                  client.getOutputStream().write(0x00); //write required endbit

                                  client.getOutputStream().flush();

                                  BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream()));

                                  //reading two lines emties flashs buffer and magically it works!

                                  in.readLine();

                                  in.readLine();

                              } catch (IOException e) {

                              }

                          }

                      }).start();

                  } catch (Exception e) {}

              }

          }