Socket ProgressEvent.SOCKET_DATA

I'm in trouble now.
see flash.net.Socket
My question:
If the data being transmitted is very small or it happens
very quickly, does ProgressEvent.SOCKET_DATA event might not be
dispatched?
Why I ask like this?
Because, see flash.net.FileReference's ProgressEvent.PROGRESS
event:
In some cases, progress events are not received. For example,
when the file being transmitted is very small or the upload or
download happens very quickly a progress event might not be
dispatched.
thanks very much.

Hi, has anyone discovered what is happening with this? I am having the same problem and also happen to be on a Vista 64bit system.
I am able to reproduce the problem quite easily for anyone that already has a server loop set up and is sending messages to their flash client.
In your flash SocketData handler function, just add a long loop, something like this:
private function onSocketData (e:ProgressEvent):void
     var count:int = 0;
     while (count < 1000*1000)
          count++;
The problem that I seem to be getting, is that in the time it takes my handler function to process the data, new data has arrived from my server loop (keeps sending messages super fast). It seems the new data is either getting queued up (although if it is, it's not being given to me in the order it arrives) or that the data is just being ignored/lost.
Does anyone have any insight on this?
I've added a delay of 100ms to the server loop and everything works fine, but this is definately not a long term solution and I've only done so to check if it is in fact the Flash side that's really buggered.
Come to think of it, I'll try making my flash side extremely fast by simply dispatching a new event on the socketdata handler and see if those events get queued and/or lost/destroyed.

Similar Messages

  • AIR: Socket ProgressEvent.SOCKET_DATA not dispatched

    Hi,
    Currently using Adobe AIR with flex 3 to communicate with a
    REST web service. I require to have full access to the HTTP header
    information to take advantage of the etag and last-modified
    information for caching. I started by using the URLRequest that
    provides the requestHeaders and using the HTTPStatusEvent with
    responseHeaders to retrieve the information. Unfortunately the
    responseHeaders are always empty, has anyone else seeing this
    problem ?
    I checked using a simple HTTP client, and the web service is
    correctly providing the HTTP headers I require.
    I decided to use sockets using the arc90 REST library:
    http://lab.arc90.com/2008/03/restservice.php
    This was all working fine...however from time to time, the
    response is never detected. More precisely the ProgressEvent is
    never fired when data is ready to read by the socket. Rooting
    around I seen this bug:
    http://bugs.adobe.com/jira/browse/SDK-14813
    From what it says there seems to be a problem with flash
    player, can anyone from Adobe provide a status on this bug ? and
    whether this is also impacting the behaviour i see in AIR ?
    I am testing AIR on Windows XP
    Thanks for any help
    James

    Sorry to reply to my own questions, but thought I would post
    this for anyone who had the same problems as I did:
    Regarding what I said....
    " I started by using the URLRequest that provides the
    requestHeaders and using the HTTPStatusEvent with responseHeaders
    to retrieve the information. Unfortunately the responseHeaders are
    always empty"
    This is true if you use:
    dispatcher.addEventListener(HTTPStatusEvent.HTTP_STATUS,
    httpStatusHandler);
    If you wish to get the response headers in AIR, you need to
    use
    dispatcher.addEventListener(HTTPStatusEvent.HTTP_RESPONSE_STATUS,
    httpStatusHandler);
    Thanks for this blog entry:
    http://www.judahfrangipane.com/blog/?p=87
    Cheers
    James

  • AS3/Sockets: more than 100 ms between ProgressEvent.SOCKET_DATA events?

    Hello,
    I'm sending images from a server, in C-berkeley sockets, to a Flash client, both on the same Linux machine:
    Average size of each package: 35000 bytes.
    Flash requests an image, and the server sends it.
    Server spends 30 ms to get,compress and send the image.
    OpenCV is used to grab each frame from a webcam.
    On Flash, first frames are received in time, every 60 ms but then the elapsed time between two reception events (ProgressEvent.SOCKET_DATA is 170 ms. So it displays images with a low frame rate.
    The visualization is not smooth but blurred.
    Anyway, the server never waits more than 40 ms to get a client's request, this is what I measure at least..., so is either Flash or server "lying" to me?
    If I connect the same Flash to a "as3-server" (OpenKinect server which gets images from the Microsoft's Kinect), everything is OK.
    Maybe there is some issue on the server side but I'm using a dedicated one with the classical functions (bind, accept, read, write and close). Any thoughts?
    Regards.

    I'm experiencing the same issue.
    I'm sending images from a C# server to an AS3 client.
    Everything is fine, with a transfert time of around 30ms per image.
    Then, for no apparent reason images take 300 or 600 or more time to get to the client.
    Then, after even some more time, it fixes itself and goes back to 30ms.
    - When everything is fine, SOCKET_DATA events contain about 24820 bytes each. (images themselves are 1 to 8MB).
    - When the problem occurs, SOCKET_DATA events contain 65636 bytes each, with occasionally lower values.
    - It is only some SOCKET_DATA events that takes long to be called back, generally one or two per image sent.
    I have series like this:
    (normal)
    socket.bytesAvailable: 24820 bytes. Inactive for 0ms.
    socket.bytesAvailable: 24820 bytes. Inactive for 0ms.
    socket.bytesAvailable: 24820 bytes. Inactive for 0ms.
    (slow)
    socket.bytesAvailable: 65536 bytes. Inactive for 0ms.
    socket.bytesAvailable: 25996 bytes. Inactive for 0ms.
    socket.bytesAvailable: 6944 bytes. Inactive for 297ms.
    socket.bytesAvailable: 65536 bytes. Inactive for 0ms.
    socket.bytesAvailable: 65536 bytes. Inactive for 0ms.
    socket.bytesAvailable: 11104 bytes. Inactive for 0ms.
    socket.bytesAvailable: 6944 bytes. Inactive for 273ms.
    socket.bytesAvailable: 65536 bytes. Inactive for 0ms.
    Where "Inactive" is the ammount of time spent between SOCKET_DATA callbacks, outside of my code.
    Some packets just take super long to be reconstructed into the byte array and sent to me in the socket data event.
    It looks like this happen after a buffer underflow.
    I have verified that this behavior is not due to Flash rendering (same problem if I don't display the images or don't do anything else).
    Currently my only viable workaround is to detect these long transferts and force a disconnection and reconnection.
    Anyone has experienced this and found a better solution or explanation ?

  • Does one socket.writeObject(obj) cause one ProgressEvent.SOCKET_DATA event?

    I use Air2.0 ServerSocket to communite with flash Socket client by using AMF.
    But network may not work correctly all the time. If one writeObject operation on client side cause 2 or more ProgressEvent.SOCKET_DATA on server side then we can not read correct object in ProgressEvent.SOCKET_DATA event handler.
    Does one socket.writeObject(obj) cause one ProgressEvent.SOCKET_DATA event?

    To submit feature requests, please visit the following page:
    http://ideas.adobe.com/air
    The AIR team actively monitors and reviews these requests.
    Rob Christensen
    Product Manager, Adobe AIR

  • ProgressEvent.SOCKET_DATA processing causes UI to be slow

    I'm working on an application using Flex Builder 2 with
    ActionScript 3. My app connects to a custom server speaking a
    proprietary protocol over a Socket. My goal is to test the
    throughput from the server to the client as it streams data,
    essentially just a stream of random bytes for now. The problem I
    have is that the client UI becomes unresponsive and fails to update
    as I spend time processing the incoming byte stream in the callback
    for ProgressEvent.SOCKET_DATA. Does anyone have any insight on this
    problem? I did a search and have seen that a few others have run
    into this issue as well, but there seems to be no resolution.
    Another note, I am working on the Windows platform, and I don't
    recall having this problem when I was running the same client code
    on a Mac. Something else I just thought of. I am testing by running
    both client and server on the same machine, and CPU is pegged at
    100%. Maybe this has an effect? I will try to change that scenario
    to isolate the problem further.
    Thanks,
    Chris Thompson

    Sorry to reply to my own questions, but thought I would post
    this for anyone who had the same problems as I did:
    Regarding what I said....
    " I started by using the URLRequest that provides the
    requestHeaders and using the HTTPStatusEvent with responseHeaders
    to retrieve the information. Unfortunately the responseHeaders are
    always empty"
    This is true if you use:
    dispatcher.addEventListener(HTTPStatusEvent.HTTP_STATUS,
    httpStatusHandler);
    If you wish to get the response headers in AIR, you need to
    use
    dispatcher.addEventListener(HTTPStatusEvent.HTTP_RESPONSE_STATUS,
    httpStatusHandler);
    Thanks for this blog entry:
    http://www.judahfrangipane.com/blog/?p=87
    Cheers
    James

  • Problem with socket responses with flex

    Hi, I am using the code below to connect to an IMAP server.
    When I telnet to the server and use the commands that I am sending in the code, the rsponses are correct.
    However, when I run the code below, I only obtain the ready and logged in responses as shown below.
    Any ideas why I am not receiving the full set of responses from the socket?
    Thanks in advance fro your advice.
    The following is the output from the code:
    +++++++++++++++++ START SENDING IMAP DATA +++++++++++++++++++++++++
    sent: . login user1 myPassword
    sent: . status INBOX (messages)
    sent: . select INBOX
    +++++++++++++++++ END SENDING IMAP DATA +++++++++++++++++++++++++
    ++++++++ [IMAP START]
    Response is: * OK Dovecot ready.
    [IMAP END] +++++++++
    ++++++++ [IMAP START]
    Response is: . OK Logged in.
    [IMAP END] +++++++++
    The code is:
    <?xml version="1.0" encoding="utf-8"?>
    <s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
       xmlns:s="library://ns.adobe.com/flex/spark"
       xmlns:mx="library://ns.adobe.com/flex/mx"
       applicationComplete="init()">
    <fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
    <fx:Script>
    <![CDATA[
    public var dataStr:String;
    private var socket:Socket;
    private var serverURL:String= "dead.org";
    private var serverPort:int = 143;
    private var serverResponse:ByteArray = new ByteArray();
    private function init():void
      this.serverURL = serverURL;
      this.serverPort = serverPort;
      socket = new Socket();
      socket.addEventListener(ProgressEvent.SOCKET_DATA,handleNewIMAPData); //Event when socket receives new data
      this.connectToServer();
      sendIMAPdata();
    private function sendString(dataStr:String):void
      var bytes:ByteArray = new ByteArray();
      bytes.writeMultiByte(dataStr, "UTF-8");
      socket.writeBytes(bytes);
      socket.flush();
      trace("sent: " + dataStr);
    public function sendIMAPdata():void
      trace("\t +++++++++++++++++ START SENDING IMAP DATA +++++++++++++++++++++++++");
      dataStr =". login user1 myPassword" + "\r\n";
      sendString(dataStr);
      dataStr =". status INBOX (messages)" + "\r\n";
      sendString(dataStr);
      dataStr =". select INBOX" + "\r\n";
          sendString(dataStr);
      trace("\t +++++++++++++++++ END SENDING IMAP DATA +++++++++++++++++++++++++");
    private function handleNewIMAPData(event:ProgressEvent):void
      var numBytes:int = socket.bytesAvailable;
      serverResponse = new ByteArray();
      while(socket.bytesAvailable)
        var byte:int = socket.readUnsignedByte();
    serverResponse.writeByte(byte);
      var response:String = serverResponse.toString();
      trace(" ++++++++ [IMAP START]\n Response is: " + response + "[IMAP END] +++++++++\n");
    private function connectToServer():void
      socket.connect(serverURL, serverPort);
    ]]>
    </fx:Script>
    </s:WindowedApplication>

    When I run telnet, the console responses are the same as the tcpdump messages.
    When I run the program, the messages from tcpdump match the messages in my trace statements.
    The messages from telnet and running the program are different:-)
    I can only assume (at the moment) that I am sending multiple messages too quickly(?), but I did a quick and dirty big "for loop" to slow down the sending of subsequent messages, but with no resulting change in the programs behaviour.
    So, still thinking about the problem -  unfortunately.

  • Sockets

    Hi,
    I'm trying to establish a socket connection to the remote server with an mobile application written in flash builder. I'm using flex 4.5 sdk.
    While running the code in mobile emulators, the socket connection is working. But after deploying the application to the phone, I get an #2031 error.
    the source code is the following:
    <?xml version="1.0" encoding="utf-8"?>
    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                   xmlns:s="library://ns.adobe.com/flex/spark">
      <fx:Style>
        @namespace s "library://ns.adobe.com/flex/spark";
        global {
          fontSize: 32;     
      </fx:Style>
      <s:layout>
        <s:VerticalLayout horizontalAlign="center" paddingTop="20"/>
      </s:layout>
      <s:TextInput id="t" text="test test"/>
      <s:Button label="create notification">
        <s:click>
          <![CDATA[
          var s:Socket = new Socket();
          s.connect("serverName", 9999);
          s.addEventListener(Event.CONNECT, function(event:Event):void {
          trace('connected!');
          t.text = "connected";
          (event.currentTarget as Socket).writeInt(1);
          (event.currentTarget as Socket).writeUTF(t.text);
          (event.currentTarget as Socket).flush();
          (event.currentTarget as Socket).close();
          s.addEventListener(IOErrorEvent.IO_ERROR, function(event:IOErrorEvent):void {
          trace('error! ' + event.errorID);
          t.text = "error! " + event.errorID;
          s.addEventListener(ProgressEvent.SOCKET_DATA, function(event:ProgressEvent):void {
          trace('progress ');
          ]]>
        </s:click>
      </s:Button>
    </s:Application>
    What am I doing wrong here?

    On mobile platforms, the app needs to request access to the internet, and the user needs to grant that permission on installation. How to request permission depends on the platform...
    The old method (for Android and IOS):
    http://help.adobe.com/en_US/air/build/WSfffb011ac560372f-5d0f4f25128cc9cd0cb-7ffe.html
    The new method (for BlackBerry PlayBook):
    http://docs.blackberry.com/en/developers/deliverables/23959/Overview_1352483_11.jsp#Access ing_secure_APIs_1524628_11

  • Socket and OutputProgressEvent.OUTPUT_PROGRESS, bytesPending

    Hi,
    I work on a projet to send large amount of data with sockets. Files are splited into bytearrays of 1 to 8 mb (to be able to resume an upload) and send with HTTP protocol.
    I think my project is correctly configured. A Flex 4.5.1 SDK updated with AIR 3, the flashplayer.swc 11 and compile with -swf-version=13.
    The new JSON feature work fine. A have an issue with the Socket.
    here is the code
    socket.addEventListener(Event.CONNECT, connectHandler);
    socket.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
    socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
    socket.addEventListener(ProgressEvent.SOCKET_DATA, socketDataHandler);
    socket.addEventListener(OutputProgressEvent.OUTPUT_PROGRESS, outputProgressHandler);
    socket.connect(host,80);
    and in the connectHandler
    socket.writeUTFBytes(requetsHeader);
    socket.writeUTFBytes("\n");
    socket.writeBytes(bytes);
    socket.writeUTFBytes("\n");
    socket.flush();
    I tried everything but the event OutputProgressEvent.OUTPUT_PROGRESS is never fired and bytesPending is always to 0.
    I'm on Windows 7 64 bits.
    thank you for your help.

    I've been trying to do a similar thing myself. This is a big problem on Windows XP as the buffer becomes blocked. This was meant to be implemented in AIR 3.

  • Make socket events OO friendly?

    Hello there,
    I'm creating an application in Air using HTML/JS and need to use sockets. I want to put the socket within a class that will provide methods for interacting with the server via the socket. The application might connect to one or more servers, using a new instance of this class for each server.
    That works fine, except for event handling. Even when I create an instance of the class, and set the eventlistener for the socket in that instance to a function of that instance, it runs that function in the context of the Eventlistener (I think, or maybe the window) instead of that particular instance whose socket fired the event.
    So, I guess what I want to know is if there's a way to bind the event listener to fire the function (onSocketConnect / onSocketData) for a particular instance of a class or not? The alternative is to use a standard function that will call those methods on all the created objects, or perhaps there might be a fancy way to determine the correct object to call?
    I'm also using the prototype library to create my class. Here is my code thus far (class names changed and irrelevant code removed:
    var MyClass= Class.create({
    initialize: function(srvr,prt){
    this.server = srvr;
    this.port = prt;
    this.sock = new air.Socket();
    //some more fields
    connect: function(){
    if (debug)
    air.trace("connect");
    this.sock.connect(this.server, this.port);
    //function to handle what needs to happen after the socket is connected
    onSocketOpen:function(event){
    if (debug)
    air.trace("onSocketOpen " + un);
    //do some stuff
    //function to handle incoming message from the server
    onSocketData: function(event){
    //do some stuff
    //bunch of other functions
    // bind function for binding objects to function calls
    Function.prototype.bind = function(o, args){
        var fn = this;
        return function(){
            fn.apply(o, args || arguments);
    var AnotherClassObject= {
        theobject: new MyClass("server", 1234),
        init: function(){
            $('btnsend').onclick = AnotherClassObject.sendEvent.bind(Irkr);
            document.body.onmousedown = function(e){
                if (e.target.tagName != 'INPUT')
                    nativeWindow.startMove();
            if (debug) air.trace("done the stuff");
    AnotherClassObject.theobject.sock.addEventListener(air.Event.CONNECT, AnotherClassObject.theobject.onSocketOpen);
    AnotherClassObject.theobject.sock.addEventListener(air.ProgressEvent.SOCKET_DATA, AnotherClassObject.theobject.onSocketData);
        AnotherClassObject. theobject.connect();
        sendEvent: function(evt){
            if (debug)
                air.trace("sendEvent");
         //do something
    //helper function to get HTML elements
    function $(id){
        if (debug)
            air.trace("$(" + id + ")");
        return document.getElementById(id);
    //run the init function when the Air window loads
    window.onload = AnotherClassObject.init;
    Thanks a lot
    Message was edited by: mushion22: Typo

    int ct = read.selectNow();
    if (ct > 0)
    Set readyKeys = read.selectedKeys();
    Iterator i = readyKeys.iterator();
    while (i.hasNext())
    SelectionKey key = (SelectionKey) i.next();
    i.remove();
    if (key.isReadable())
    SelectableChannel nextReady = (SelectableChannel) key.channel();
    SocketChannel sc = (SocketChannel) key.channel();
    int rd = sc.read(buffer);
    // Link is dead
    if (rd == -1)
    key.cancel();
    key.attach(null);
    nextReady.close();
    continue;
    // Process your data
    catch (Exception e)
    e.printStackTrace();

  • How to enable socket connection?

    I have allowed INTERNET permission, but my socket still blocked.
         <uses-permission android:name="android.permission.INTERNET" />
    If I compile apk with -debug tag, then socket connection works, but my application runs very slow.
    And I dont want to publish a release version with all my debug messages.
    What is the standard way to open socket connection?
    Thanks

                   var s:Socket=new Socket();
                    s.connect("ip_address", "port_number");
                    s.addEventListener(Event.CONNECT, function(event:Event):void{
                        trace('connected!');
                    s.addEventListener(IOErrorEvent.IO_ERROR, function(event:IOErrorEvent):void{
                        trace('error! ' + event.errorID);
                    s.addEventListener(ProgressEvent.SOCKET_DATA, function(event:ProgressEvent):void{
                        var str:String=(event.currentTarget as Socket).readUTF();
    There are examples out there.  Fire up Google Search .

  • Simple Socket Question / Error...

    I'm testing out a socket connection for an RDP app on the playbook.
    Flash Builder Burrito 4.5
    Adobe AIR SDK 2.5 Hero
    Playbook SDK 0.9.2
    Playbook Sim 0.9.2
    VMPlayer running in Bridged Networking mode
    public function RDPApp()
                   var socket:Socket = new Socket();
                   socket.addEventListener(Event.CONNECT, onConnect);
                   socket.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
                   socket.addEventListener(Event.CLOSE, onClose);
                   socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecurityError);
                   socket.addEventListener(ProgressEvent.SOCKET_DATA, onReceivedData);
                   socket.connect("http://www.google.com", 80);
                   socket.close();
                   stage.nativeWindow.visible = true;
              private function closeWindow(event:MouseEvent):void{
                   stage.nativeWindow.close();
              protected function onConnect(event:Event):void
                   // TODO Auto-generated method stub
              protected function onIOError(event:IOErrorEvent):void
                   trace(event);
              protected function onClose(event:Event):void
                   // TODO Auto-generated method stub
              protected function onSecurityError(event:SecurityErrorEvent):void
                   // TODO Auto-generated method stub
              protected function onReceivedData(event:ProgressEvent):void
                   // TODO Auto-generated method stub
    The code above throws on the sim and on the desktop:
    IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2031: Socket Error. URL:http://www.google.com" errorID=2031]
    Googling this error message indicates that the client flash app has not received the required policy file from the server.
    I was under the impression that AIR apps running on the desktop sandbox (Playbook included) do not require the retrieval of the policy file.
    Any help is much appreciated.
    Matt

    For sockets you need to first load the securitypolicy file then call methods on it.
    ref : http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/Socket.html
    Message was edited by: saisri2k2

  • Socket and Security Policy

    I've tried to set experiment with Socket communication in Flex, but I keep hitting problems. Approach 1: in a Flex web app, I load a crossdomain security policy from a server. I then open a socket and write a few bytes to the server. In my server, I do not get the expected output on the stream--in fact, I get nothing at all--until I close the Flex application, at which point I get a seemingly inifinite stream of the bytes '0xEFBFBF'. Here's a hexdump view of a fragment of the data Flash Player sends to the server after I close the Flex app:
    00000130  ef bf bf ef bf bf ef bf  bf ef bf bf ef bf bf ef  |................|
    00000140  bf bf ef bf bf ef bf bf  ef bf bf ef bf bf ef bf  |................|
    00000150  bf ef bf bf ef bf bf ef  bf bf ef bf bf ef bf bf  |................|
    Approach 2: I then tried it in air, but although the connection seems to initiate properly and I can go through the above trivial client-server interaction, after a few seconds, I get a SecurityErrorEvent. From what I've been able to follow of the docs, Air applications are trusted in this respect, and should not need to load security policy, right? I tried to add a call to Security.loadPolicy(), but it seems to be ignored. This is the message flow:
    Received [class Event] connect
    Received [class ProgressEvent] socketData
    Received [class Event] close
    Received [class SecurityErrorEvent] securityError
    Security error: Error #2048: Security sandbox violation: app:/main.swf cannot load data from localhost:5432.
    The Air version of my client code is below:
    <?xml version="1.0" encoding="utf-8"?>
    <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
    <mx:Script>
        <![CDATA[
            var str:Socket;
            private function handleClick(e:Event):void {
                Security.loadPolicyFile("xmlsocket://localhost:2525");           
                str = new Socket('localhost', 5555);
                var message:String = 'hello';
                for (var i:int = 0; i < message.length; i++) {
                    str.writeByte(message.charCodeAt(i));               
                str.writeByte(0);
                str.flush();
                str.addEventListener(Event.ACTIVATE, handleEvent);
                str.addEventListener(Event.CLOSE, handleEvent);
                str.addEventListener(Event.CONNECT, handleEvent);
                str.addEventListener(Event.DEACTIVATE, handleEvent);
                str.addEventListener(IOErrorEvent.IO_ERROR, handleEvent);
                str.addEventListener(ProgressEvent.SOCKET_DATA, handleEvent);
                str.addEventListener(SecurityErrorEvent.SECURITY_ERROR, handleEvent);           
            private function handleEvent(e:Event):void {
                 trace("Received", Object(e).constructor, e.type);
                 if (e is ProgressEvent) {
                     var strBytes:Array = [];
                     while(str.bytesAvailable > 0) {
                         var byte:int = str.readByte();
                         strBytes.push(byte);
                     trace(String.fromCharCode.apply(null, strBytes));
                 } else if (e is SecurityErrorEvent) {
                     trace("Security error:", SecurityErrorEvent(e).text);
        ]]>
    </mx:Script>
    <mx:Button label="test" click="handleClick(event)"/>   
    </mx:WindowedApplication>
    The server is in Java and is as follows:
    import java.net.*;
    import java.io.*;
    public class DeadSimpleServer implements Runnable {
        public static void main(String[] args) throws Exception {
            if (args.length != 2) {
                throw new Exception("Usage: DeadSimpleServer policy-port service-port");
            int policyPort = Integer.parseInt(args[0]);
            int servicePort = Integer.parseInt(args[1]);
            new Thread(new DeadSimpleServer(policyPort,
                                            "<?xml version=\"1.0\"?>\n" +
                                            "<cross-domain-policy>\n" +
                                            "<allow-access-from domain=\"*\" to-ports=\"" + servicePort + "\"/>\n" +
                                            "</cross-domain-policy>\n"
                       ).start();
            new Thread(new DeadSimpleServer(servicePort, "world")).start();
            while (true) Thread.sleep(1000);
        private int port;
        private String response;
        public DeadSimpleServer(int port, String response) {
            this.port = port;
            this.response = response;
        public String getName() {
            return DeadSimpleServer.class.getName() + ":" + port;
        public void run() {
            try {
                ServerSocket ss = new ServerSocket(port);
                while (true) {
                    Socket s = ss.accept();
                    System.out.println(getName() + " accepting connection to " + s.toString());
                    OutputStream outStr = s.getOutputStream();
                    InputStream inStr = s.getInputStream();
                    int character;
                    System.out.print(getName() + " received request: ");
                    while ((character = inStr.read()) != 0) {
                        System.out.print((char) character);
                    System.out.println();
                    Writer out = new OutputStreamWriter(outStr);
                    out.write(response);
                    System.out.println(getName() + " sent response: ");
                    System.out.println(response);
                    System.out.println(getName() + " closing connection");
                    out.flush();
                    out.close();
                    s.close();
            } catch (Exception e) {
                System.out.println(e);
    Am I missing something? From what I understand, either of these approaches should work, but I'm stuck with both. I have Flash Player 10,0,15,3 and am working with Flex / Air 3.0.0 under Linux.

    So... apparently, with the Air approach, this is what I was missing: http://www.ultrashock.com/forums/770036-post10.html
    It'd be nice if FlashPlayer gave us a nicer error here.
    I'm still trying to figure out what the heck is going on in the web app (i.e., non-Air Flex) example. If anyone has any suggestions, that would be very helpful.

  • Slow download on Mac and Linux using sockets

    We have a need to download as much as possible for a couple seconds using sockets, and we have noticed that Adobes flash player on Mac and Linux are slower then Windows while we get good results on all tree OS using Goggles flash player in Chrome.
    Our setup, client side, is a 1 Gbit/s internet connection throttle by a 100 Mbit/s switch. On the server side, we have an Apache web server (during testing) on a 1 Gbit/s internet connection.
    For testing purposes, we download as much as possible of a 2 Gb big file for approximately 10 seconds. After we connect to the server, via a socket, we send an http request to start downloading the file. Using bytesAvailable, we get the number of bytes downloaded every half second, calculate the average speed for that half second and store that value in an array. After 20 times, we stop downloading and close the socket connection. Finally we calculate the average download speed of the 20 measurements.
    All tests are preformed on version 11.6.602.180 except for Adobe Flash player on Ubuntu were the 11.2 r202 version. Adobe Flash player on Firefox 19.0.2 (other browsers were tested with similar results) and Google Flash player on Chrome 26.0.1410.43. Each OS/player was tested 5 times and presents the average.
    Windows 7 Enterprise (64-bit) 
    Mac OS X 10.6.8 (64 bit) 
    Ubuntu 12.10 (64 bit) 
    Adobe Flash player (NPSWF32_11_6_602_180.dll)
    92.73 Mbit/s 
    14.53 Mbit/s 
    44.25 Mbit/s 
    Google Flash player (pepflashplayer.dll)
    91,89 Mbit/s 
    89.46 Mbit/s 
    91.57 Mbit/s 
    doConnect();
    function doConnect():void {
        socket = new Socket(url,port);
        socket.addEventListener(Event.CONNECT, connectHandler);
    function connectHandler(event:Event):void {
        writeln("GET " + path + " HTTP/1.1");
        writeln("Host: " + url);
        writeln("Connection: close");
        writeln("");
        nStart = new Date().time;
        startTimer();
        socket.flush();
    function writeln(str:String):void {
        str +=  "\n";
        socket.writeUTFBytes(str);
    function startTimer(){
        startTime = new Date().time;
        var myTimer:Timer = new Timer(500,20);// 0.5 seconds 20 times
        myTimer.addEventListener(TimerEvent.TIMER, timeMeasurement);
        myTimer.addEventListener(TimerEvent.TIMER_COMPLETE, timeMeasurementComplete);
        myTimer.start();
    function timeMeasurement():void {
        receivedData = socket.bytesAvailable;
        var varJunk:ByteArray = new ByteArray();
        while (socket.bytesAvailable > 4){
            socket.readBytes(varJunk);
        var split:Number = new Date().time - startTime;
        var speed:Number = receivedData * 8 / ((new Date().time - startTime) / 1000);
        startTime = new Date().time;
        downloadList.push(speed);
        receivedData = 0;
    function timeMeasurementComplete():void{
        var len:int = downloadList.length;
        var sum:Number = 0;
        for (var i:int = 0; i < len ; i++) {
            sum +=  downloadList[i];
        downloadResult = sum / len;
        socket.removeEventListener(Event.CONNECT, connectHandler);
        if(socket.connected){
            socket.close();
    In further investigation we built an easy Flash based latency meter. We download a small txt-file, measuring the time between just before we send http-request and until we receive a response from the web server.
    We have the setup as for the speed tests, but we do this 5 * 20 times with each OS/player.
    Windows 7 Enterprise (64-bit) 
    Mac OS X 10.6.8 (64 bit) 
    Ubuntu 12.10 (64 bit) 
    Adobe Flash player 
    4.30 ms 
    66.67 ms 
    10.49 ms 
    Google Flash player 
    4.25 ms 
    4.28 ms 
    4.19 ms 
    doConnect();
    private function doConnect():void{
        socket = new Socket(url,port);
        socket.addEventListener(Event.CONNECT, connectHandler);
        socket.addEventListener(ProgressEvent.SOCKET_DATA, socketDataHandler);
    private function connectHandler(event:Event):void{
        writeln("GET " + path + " HTTP/1.1");
        writeln("Host: " + url);
        socket.flush();
        nStart = new Date().time;
    private function writeln(str:String):void{
        str +=  "\n";
        socket.writeUTFBytes(str);
    private function socketDataHandler(event:ProgressEvent):void{
        var latecy:Number = new Date().time - nStart; // latency in ms
    Using a packet analyzer (Wireshark) on the OS X/Adobe player, the time from http-request is sent to data is received is approximately 2 ms. An ack is sent less then 0.04 ms after the packet is received. Using the socketData event to send a new http-request, just after we measure the time for the last package, can see event created delays. We have a delay between 64 and 67 ms compare that to OS X/Google player with between 1 and 3 ms delay.
    Note: When playing around a timer, that fired a number of times during parts of a large number of latency measurements, we notice that measurements when the timer was running were better. Testing having a empty timer firing as fast as possible constantly during both download and latency measurements we got significantly better results on OS X/Adobe player, although not good. Average download 31,82 Mbit/s and average latency 16,59 ms.

    Bumping this topic again as it's still sort of bugging me, but the problem has been isolated to a few certain sites. On some i get the maximum speed and on others i get snailspeed. One of the slow ones unfortunately is basically anything that has to do with Apple....So all Quicktime movie trailers, iTunes stuff, movies etc are slow, except podcasts that are German. I'm downloading the 30 day trial of iWork and i'm getting whopping 19,2KB/s, when i should be getting about 1300KB/s. You can just imagine the frustration:/
    I'm just wondering am i alone on this or is anybody else excperienceing similar? And as usual, on windows i'm getting full speed all the time, anywhere, grrrr....!
    -CC

  • Javascript Socket Obj and Port 21

    I'm just trying to open a socket connection to an ftp server
    on port 21. I've read that people have had success over flex/flash,
    but I haven't been able to connect to port 21 with Javascript and
    there are no events or error messages associated with trying.
    I'd just like to know if its currently possible.

    Yes, you can use the Socket class to connect to an FTP server
    in JavaScript:
    var socket = new air.Socket("ftp.cs.berkeley.edu", 21);
    socket.addEventListener(air.Event.CONNECT, connected);
    socket.addEventListener(air.ProgressEvent.SOCKET_DATA,
    dataHandler);
    socket.addEventListener(air.IOErrorEvent.IO_ERROR,
    errorHandler);
    socket.addEventListener(air.SecurityErrorEvent.SECURITY_ERROR,
    securityErrorHandler);

  • Binary Socket Security

    Hello,
    The documentation is a bit sparse on what to do with binary sockets and the security model.  Particularily what it means to 'return a cross domain policy file' ( See Section 1.4.3 and 1.5.6 of Cross Domain Policy File Documentation http://learn.adobe.com/wiki/download/attachments/64389123/CrossDomain_PolicyFile_Specifica tion.pdf?version=1 )
    This is what my socket server code looks like in PHP:
    (PHP)
    if (strcmp( substr($input,0,22), "<policy-file-request/>") == 0 ){              
         socket_write($socket,"<?xml version=\"1.0\"?>\n<!DOCTYPE cross-domain-policy SYSTEM\n\"http://www.adobe.com/xml/dtds/cross-domain-policy.dtd\">\n<cross-domain-policy>\n<allow-access-from domain=\"*\" to-ports=\"4041\"/>\n</cross-domain-policy>\n\n");
    When I run my AS3 code
    var socket:Socket = new Socket();      
    socket.endian = Endian.BIG_ENDIAN;
    socket.addEventListener(Event.CLOSE, close);
    socket.addEventListener(Event.CONNECT, connected);
    socket.addEventListener(IOErrorEvent.IO_ERROR, io_error );
    socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, security_error );
    socket.addEventListener(ProgressEvent.SOCKET_DATA, socket_data);   
    socket.addEventListener(Event.DEACTIVATE, close);
    socket.timeout = 3000;
    socket.connect(host,4041);      
    The client does ask for the security file,  but after the server writes the security file to the socket the client socket shuts down and returns a security error.
    What am I doing wrong?  Should the server be outputting a URL where the crossdomain.xml is located instead?  I don't understand what nuance I am missing.
    Could someone please explain what I am missing?
    Thanks

    My problem was that I was sending binary data through the socket previous to sending the policy file.  I just sent the policy file immediately upon connect and everything worked out fine.   I had to add a chr(0) to the end of the policy file as well.
    Thanks for your time.

Maybe you are looking for

  • Name and int using a String

    Hi everybody, ive got a class that creates a new int. i want the name of the int to be a parameter that i can send into the class. so for example: public testObject(String intName) then in my main I could say: testObject grader = new testObject(grade

  • Motion and Final Cut Pro Problem

    I recently updated my computer and went with the new Quad-Core Mac. I had to reload the Final Cut Pro Studio software, and I've got a problem that is vexing me to no end. I can import a Motion template (one that I've designed and even the Apple produ

  • Maximum Line items for Equipment BOM

    Dear Experts, Is there a limit to the number of line items of components we can have in equipment BOM. I am not able to add anything above 999. It doesnt show any error, but doesnot save any value after 999. Please let me if there is a work around. T

  • Yosemite: Western Digital External Drives fully supported?

    I use a Western Digital My Book Studio Edition II 2TB via FireWire as my TimeMachine backup drive. I still run Mavericks on my iMac 27" 2012 model (Core i5, 2.9 Ghz, 8GB Ram, 1TB Fusion drive). It had no problems with Mavericks since I updated to wd

  • 404 error after restoring the database

    Friends, our dba team restored the Flows_030000 schema after a complete monthly refresh of our server (RMAN restore). Now when I try to access the APEX admin page or any of the applications it gives me a 404 error saying '/pls/apex/apex_admin/ was no