Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6990135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:18:28+00:00 2026-05-27T19:18:28+00:00

I have a Groovy server and Flex client. When i try to connect from

  • 0

I have a Groovy server and Flex client. When i try to connect from Flex to Groovy application, i reveive <policy-file-request/> message. Then i send some policy XML response and try to send something to the server. But instead of receiving something on the Groovy side i get absolutely nothing. And after a few seconds i get a SecurityException on the Flex application side.

Groovy server code:

import java.util.Scanner

class server
{
    public static handleConnection(client)
    {
        PrintWriter socketwriter = new PrintWriter(client.getOutputStream())

        Scanner socketreader = new Scanner(client.getInputStream())

        while (socketreader.hasNext())
        {
            String s = socketreader.nextLine()

            println s

            if (s =~ /<policy-file-request\s*\/>/)
            {

                socketwriter.print("<?xml version=\"1.0\"?><!DOCTYPE cross-domain-policy SYSTEM \"/xml/dtds/cross-domain-policy.dtd\"><cross-domain-policy><site-control permitted-cross-domain-policies=\"master-only\" /><allow-access-from domain=\"*\" to-ports=\"2900-2910\" /></cross-domain-policy>\n\0\n")

                socketwriter.flush()
                socketwriter.close()
                client.close()

                println "Policy File sent."

                return
            }
        }

        socketwriter.print("Connection: Done.\n")
        socketwriter.flush()

        socketwriter.close()
        socketreader.close()
    }

    static main(args)
    {
        ServerSocket serversocket

        try
        {
            serversocket = new ServerSocket(2900)

            println "Server is up and running"

            while (true)
            {
                Socket client = serversocket.accept()

                Thread.start {
                    server.handleConnection(client)
                }
            }
        } catch (e)
        {
            e.printStackTrace()
        } finally
        {
            serversocket.close()
        }
    }
}

Flex client code:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
    <mx:Script>
        <![CDATA[
            import flash.net.Socket;
            import flash.events.*;
            import mx.controls.Alert;

            private var socket : Socket;

            private function connect() : void 
            {
                socket = new Socket();

                socket.addEventListener(Event.CONNECT, onConnect);
                socket.addEventListener(ProgressEvent.SOCKET_DATA, onSocketData);
                socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, ServerSecurityError);

                socket.connect("localhost", 2900);

                Alert.show("yay!");
            }

            private function ServerSecurityError(evt : Event) : void
            {
                Alert.show("security error")
            }

            private function onConnect(evt : Event) : void
            {
                Alert.show("Connected to server!");
            }

            private function onSocketData(evt : ProgressEvent) : void
            {
                var data : String = socket.readUTFBytes(socket.bytesAvailable);
                Alert.show("Read: " + data);
            }

            private function send() : void 
            {
               var msg : String = "Hello, World!";
               socket.writeUTFBytes(msg);
               socket.flush();
               Alert.show("Sent: " + msg);
            }
        ]]>
    </mx:Script>

    <mx:Button label="connect" click="connect()" x="10" y="10" />
    <mx:Button label="send something" click="send()" x="10" y="40" />
</mx:Application>

So, the question is: How should i connect to get a stable communication between server and client?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T19:18:28+00:00Added an answer on May 27, 2026 at 7:18 pm

    A SecurityError occurs for the following reasons (from the docs):

    • Local untrusted SWF files cannot communicate with the Internet. You
      can work around this limitation by reclassifying the file as
      local-with-networking or as trusted.
    • You cannot specify a socket port
      higher than 65535.
    • In the HTML page that contains the SWF content,
      the allowNetworking parameter of the object and embed tags is set to
      “none”.

    We’re running a similar setup (using a pure AS3 frontend), and before I make the call to connect(), I call:

    Security.loadPolicyFile( "xmlsocket://" + this.m_host + ":" + this.m_policyFilePort );

    where m_host can be something like “localhost” and m_policyFilePort is whatever port you’re serving it on. You can find more on it here, or at the Socket files

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm starting to learn Groovy with a Client-Server architecture. As the server I have
I'd like to add groovy-shell-server to our application. We have run into a couple
I have a groovy/grails application that needs to serve images It works fine on
I have a Groovy application for Windows and am trying to convert a Hash
DB: Sql Server 2008. I have a really (fake) groovy query like this:- SELECT
I was trying to connect with groovy WSClient to Exchange server wsdl, but can't
I have developed a grails/groovy application for a legacy database which has user maintenance
We have developed a Groovy application. Under development for starting it we use the
I want to create excel files in Groovy, then have them plotted. This code
I have a groovy script with an unknown number of variables in context at

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.