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 800521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T23:18:09+00:00 2026-05-14T23:18:09+00:00

I am implementing a simulated b/s stock data system. I am using flex and

  • 0

I am implementing a simulated b/s stock data system. I am using flex and c# for client and server sides. I found flash has a security policy and I handled the policy-file-request in my server code. But seems it doesn’t work, because the code jumped out at “socket.Receive(b)” after connection. I’ve tried sending message on client in the connection handler, in that case the server can receive correct message. But the auto-generated “policy-file-request” can never be received, and the client can get no data sending from server. Here I put my code snippet.

my ActionScript code:

public class StockClient extends Sprite {
    private var hostName:String = "192.168.84.103";
    private var port:uint = 55555;
    private var socket:XMLSocket;

    public function StockClient() {
        socket = new XMLSocket();
        configureListeners(socket);
        socket.connect(hostName, port);
    }

    public function send(data:Object) : void{
        socket.send(data);
    }

    private function configureListeners(dispatcher:IEventDispatcher):void {
        dispatcher.addEventListener(Event.CLOSE, closeHandler);
        dispatcher.addEventListener(Event.CONNECT, connectHandler);
        dispatcher.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
        dispatcher.addEventListener(ProgressEvent.PROGRESS, progressHandler);
        dispatcher.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
dispatcher.addEventListener(ProgressEvent.SOCKET_DATA, dataHandler);
    }

    private function closeHandler(event:Event):void {
        trace("closeHandler: " + event);
    }

    private function connectHandler(event:Event):void {
        trace("connectHandler: " + event);
        //following testing message can be received, but client can't invoke data handler
//send("<policy-file-request/>");
    }

    private function dataHandler(event:ProgressEvent):void {
        //never fired
        trace("dataHandler: " + event);
    }

    private function ioErrorHandler(event:IOErrorEvent):void {
        trace("ioErrorHandler: " + event);
    }

    private function progressHandler(event:ProgressEvent):void {
        trace("progressHandler loaded:" + event.bytesLoaded + " total: " + event.bytesTotal);
    }

    private function securityErrorHandler(event:SecurityErrorEvent):void {
        trace("securityErrorHandler: " + event);
    }
}

my C# code:

    const int PORT_NUMBER = 55555;
    const String BEGIN_REQUEST = "begin";
    const String END_REQUEST = "end";
    const String POLICY_REQUEST = "<policy-file-request/>\u0000";
    const String POLICY_FILE = "<?xml version=\"1.0\"?>\n" +
        "<!DOCTYPE cross-domain-policy SYSTEM \"http://www.adobe.com/xml/dtds/cross-domain-policy.dtd\">\n" +
        "<cross-domain-policy> \n" +
        " <allow-access-from domain=\"*\" to-ports=\"55555\"/> \n" +
        "</cross-domain-policy>\u0000";           
    ................

    private void startListening()
    {
        provider = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
        provider.Bind(new IPEndPoint(IPAddress.Parse("192.168.84.103"), PORT_NUMBER));
        provider.Listen(10);
        isListened = true;

        while (isListened)
        {
            Socket socket = provider.Accept();
            Console.WriteLine("connect!");
            byte[] b = new byte[1024];
            int receiveLength = 0;
            try
            {
                // code jump out at this statement
                receiveLength = socket.Receive(b);
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.ToString());
            }
           String request = System.Text.Encoding.UTF8.GetString(b, 0, receiveLength);

            Console.WriteLine("request:"+request);

            if (request == POLICY_REQUEST)
            {
                socket.Send(Encoding.UTF8.GetBytes(POLICY_FILE));
                Console.WriteLine("response:" + POLICY_FILE);
            }
            else if (request == END_REQUEST)
            {
                Dispose(socket);
            }
            else
            {
                StartSocket(socket); break;
            }
        }
    }

Sorry for the long code, please someone help with it, thanks a million

  • 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-14T23:18:10+00:00Added an answer on May 14, 2026 at 11:18 pm

    that is because the socket policy file isn’t requested on the port you are trying to join, but on the static port 843.

    You should listen to port 843 to serve the policy requests. Also, I had some problems when immediately closing the socket after having sent the policy file. It seems that the socket should be left open for a few seconds after the policy file had been sent, otherwise Flash might simply drop the answer.

    Note that this way, you can serve policy file requests from another application, not necessary from your main server.

    The whole stuff is described in this documentation.

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

Sidebar

Related Questions

I'm implementing back-end data loading with a server by creating an NSOperation and opening
I'm implementing piping on a simulated file system in C++ (with mostly C). It
I am implementing 2-phase commit for a distributed transaction(using 2 Databases). I simulate a
implementing publishActivity in PHP using the REST API using this code: $activity = array(
Implementing a simple Login screen using JSF and Spring and Hibernate. I have written
When implementing a hash table using a good hash function (one where the probability
Before implementing j_security_check using MySQL realm authentication in my web app. I had the
Implementing the basic algorithm using last array as a pivot in Java, is it
When implementing iterator using yield return , is there any difference between returning IEnumerator
My java application currently has an icon in the system tray. When the system

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.