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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:09:43+00:00 2026-05-22T01:09:43+00:00

I have a socket server listening on 2 ports, 1 port for the socket

  • 0

I have a socket server listening on 2 ports, 1 port for the socket server and 1 port for the policy server.

My code is below, in this scenario, data is sent and received perfectly fine. however, for example if I add a button with a simple:


socket.writeUTFBytes("Message");
socket.flush();

after the initial connection, it doesn’t seem to send any data to my server (I have my server printing all data transmissions to the console for checking) Initial connections work fine, as seen below:


//authenticate with socket server first:
var xmlSocket = new XMLSocket();
xmlSocket.connect("192.xx.xx.xx", 843);

try {
    Security.loadPolicyFile("xmlsocket://192.xx.xx.xx:843");
} catch (e:IOError) {
    //tbOutput.text += e.text;
}


var socket:Socket = new Socket();
socket.addEventListener(Event.CONNECT, onConnect);
socket.addEventListener(Event.CLOSE, onClose);
socket.addEventListener(IOErrorEvent.IO_ERROR, onError);
socket.addEventListener(ProgressEvent.SOCKET_DATA, onResponse);
socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecError);

try {
socket.connect("192.xx.xx.xx", 4444);
} catch (e:IOError) {
    //error traced
}


function onConnect(e:Event):void {
    //initial message to socket server:
    var Message:String;
    //message contains something
    socket.writeUTFBytes(Message.toString() + "<EOF>");
    socket.flush();

    }

  • 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-22T01:09:44+00:00Added an answer on May 22, 2026 at 1:09 am

    You basically have it right you just missed something.
    The initial connection is saved for the crossdoamin file even is you specify another port it will try to get the file from 4444 first and if that fails then it will go for the master on the default port(843).
    Here is your offending line

    Security.loadPolicyFile("xmlsocket://192.xx.xx.xx:843");
    

    If you look at your server logs you will find that when the first connection was made there was a request in the form of <policy-file-request/> made to the server.
    Once that request is completed and the file delivered to the client then the connection will be closed by the client always.
    On the client side once the crossdomain is received and the connection closed you can then reconnect and send at will.

    So to recap.
    Your flash app made a connection to the server.
    Then your app requested the crossdomain and sat and waited
    Before the connection timed out you then proceeded to send data of some sort over your the connection
    The app still waiting for the cross domain received a response from your server
    Since the data received from the server is not the crossdomain.xml file your app closed the connection and will not allow reconnects

    I changed your code a bit to auto reconnect
    However your server on port 4444 should return the crossdomain file when there is a request for it.

    try {
      Security.allowDomain('192.xx.xx.xx');
      Security.loadPolicyFile("xmlsocket://192.xx.xx.xx:4444");
    } catch (e:IOError) {
        //tbOutput.text += e.text;
    }
    
    
    var socket:Socket = new Socket();
    socket.addEventListener(Event.CONNECT, onConnect);
    socket.addEventListener(Event.CLOSE, onClose);
    socket.addEventListener(IOErrorEvent.IO_ERROR, onError);
    socket.addEventListener(ProgressEvent.SOCKET_DATA, onResponse);
    socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecError);
    
    function connect( ){
      if( !socket.connected ){
        try {
          socket.connect("192.xx.xx.xx", 4444);
        } catch (e:IOError) {
          //error traced
        }
      }
    }
    
    function onConnect(e:Event):void {
        //initial message to socket server:
        var Message:String;
        //message contains something
        //socket.writeUTFBytes(Message.toString() + "<EOF>");// EOF bad
        socket.writeUTFBytes(Message.toString() + String.fromCharCode(0) ); // NULL good
        socket.flush();
    
    }
    
    function onResponse(e:ProgressEvent):void {
      var read:String = this.readUTFBytes(this.bytesAvailable );
    
      // I test for a < since my server will never return a "<" as the first character
      // unless it is the crossdomain.xml file
      // you may need to change this for your needs
      if( read.charAt(0) !='<' ){
        if( read ){
          // so something with your response
        }
      }else{
        // recieved crossdomain policy nothing to really do here it is handled internally
      }
    }
    
    
    var connectTimer:Timer = new Timer( 1000 );
    connectTimer.addEventListener(TimerEvent.TIMER, connect );
    connectTimer.start();
    

    Don’t forget for this to work your server on port 4444 needs to return the crossdomain file on that port

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

Sidebar

Related Questions

I have a 'C# server' program listening to '127.0.0.1', port 5500, using .NET socket,
Let's say I have a server socket listening on port no 5010. When client
I have this code for Server in socket programming application, and I have this
I have to create an sample code that connect to a socket server, and
I have a server that sends data via a socket, the data is a
I've got this code in my socket class: bool GSocket::Listen(int Port) { d->Socket =
Possible Duplicate: Java socket sends some data during connection to server I have two
I have Nginx as my front-end web server listening on port 80. And certain
I have a listening port on my server that I'm connecting to using a
In my socket code I have the following structure: Server: #include <stdio.h> #include <stdlib.h>

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.