• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
Locked
0

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

Explorer ,
May 04, 2015 May 04, 2015

Copy link to clipboard

Copied

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

Views

216

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Explorer , May 05, 2015 May 05, 2015

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(){

    ServerSocke

...

Votes

Translate

Translate
Explorer ,
May 05, 2015 May 05, 2015

Copy link to clipboard

Copied

LATEST

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) {}

    }

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines