3 Replies Latest reply on Jul 27, 2009 7:18 AM by Lopo Nopo

    An app using Socket is acting wierd.

    Lopo Nopo Level 1



      I have a client application which connects to a server over raw sockets using TCP/IP protocol (bottom line I connect with class Socket).


      It works perfectly, graphics are just fine.


      When launched from the hard-disk there are no data transfer problems between the app and the server.


      My problemt starts when I'm testing it through an HTTP server, i.e writing the URL;


      Then the app sends to the server some unrelated binary data.

      For example; If this app would send "hello" under normal circumstances then now, when launched from an HTTP server it would send "%*&@#" (not really these chars, imagine binary chars as well).


      I've checked the Endian property and on both server & client their the same.

      The client does use the ByteStream.writeInt() on the first message, the one which cuts the whole operation.


      Is there any rule or something that would affect the data being sent?



      Remember when I say that launching this SWF file from the hard-disk by double-clicking or dragging it to the web-browser it works perfectly.


      That's a very odd behaviour I have to resolve.

        • 1. Re: An app using Socket is acting wierd.
          Lopo Nopo Level 1

          I've written an echo server (c++) and a chat client (flex) to see what's going on.

          The results:



          Some smarty at Adobe () is really trying to make it hard for us!

          What the heck is this?


          Upon connection the flex client sends this string (without quotes) to the server and disconnects.


          Can anyone tell me how to deal with this?

          It REALLY ruins a LOT to me here - I mean, the socket communication is binary and now I have to do some string manipulation, detect this state etc' etc'........


          I'm googling right now for this but from what I've seen so far - this "smarty" feature of flex is going to drive me crazy.


          Thanks a lot "designer", you, who decided to do things this way.


          I'll be HAPPY to know how to avoid it.

          • 2. Re: An app using Socket is acting wierd.
            Lopo Nopo Level 1

            Hey again, I've been trying to deal with this for several hours now with absolutely no success.

            I even created a whole socket client app (with flex) so I can try this, and the code is below.


            I'll give here the parameters hoping someone is able to give a useful advice;


            Client source code:


            <?xml version="1.0" encoding="utf-8"?>
            <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="481" height="330"
                <mx:TextInput x="48" y="8" id="txtHost" text=""/>
                <mx:Label x="10" y="10" text="Host"/>
                <mx:Label x="216" y="10" text="Port"/>
                <mx:NumericStepper x="251" y="8" minimum="0" maximum="65535" stepSize="1" id="numPort" value="5634"/>
                <mx:Button x="338" y="8" label="Connect" id="cmdConnect" click="OnCmdConnect()"/>
                <mx:TextArea x="10" y="36" width="461" height="254" id="txtLog"/>
                <mx:TextInput x="10" y="298" width="461" id="txtInput" keyDown="OnInputKeyDown(event)"/>
                        private var sock:Socket = null;
                        private function OnInitDone():void
                            sock = new Socket;
                            sock.addEventListener(flash.events.ProgressEvent.SOCKET_DATA, sockEVENT);
                            sock.addEventListener(flash.events.Event.CONNECT, sockEVENT);
                            sock.addEventListener(flash.events.Event.CLOSE , sockEVENT);
                            sock.addEventListener(flash.events.IOErrorEvent.IO_ERROR, sockEVENT);
                            sock.addEventListener(flash.events.SecurityErrorEvent.SECURITY_ERROR , sockEVENT);
                        private function OnCmdConnect():void
                            var szPolicyFileUrl:String = "http://" + this.txtHost.text + ":" + "80" + "/crossdomain.xml";
                            //var szPolicyFileUrl:String = "xmlsocket://" + this.txtHost.text + ":" + "80" + "/crossdomain.xml";
                            sock.connect(this.txtHost.text, this.numPort.value);
                        private function OnInputKeyDown(event:KeyboardEvent):void
                            if(event.keyCode == 13)
                                    this.txtInput.text = "";
                        private function LogIt(txt:String):void
                            this.txtLog.text += txt + "\n";
                        private function sockEVENT(e:Event):void
                            switch (e.type)
                                case ProgressEvent.SOCKET_DATA :
                                    if(sock.bytesAvailable == 0)
                                    var tmp:String = sock.readUTFBytes(sock.bytesAvailable);
                                case Event.CONNECT :
                                    LogIt("Connection initiated");
                                case Event.CLOSE :
                                case IOErrorEvent.IO_ERROR :
                                case SecurityErrorEvent.SECURITY_ERROR :






            A "crossdomain.xml" file:


            <?xml version="1.0"?>
                <site-control meta-policy="all"/>
                <allow-access-from domain="*" to-ports="5634"/>



            Now, on a local machine I fire up an HTTP daemon, such as Apache.

            It serves the "bin-debug" folder of this Flex project.

            I load the SWF at my browser.


            That's for the client.


            On the server:

            An HTTP daemon serving the "crossdomain.xml" file on port 80.

            On that machine as well I have an echo server, listening on port 5634.



            Now, at the client app I simply click "Connect" (after setting up the ip & the port).

            Using TCPView (by Sysinternals) I can see that Flash is trying to connect port 843, 80 and 5634.


            First dumb thing - why Flash tried to connect on port 843 when I specifically told it to use port 80?!


            Secondly - why does this Flash writes to the binary server (at port 5634) the string




            Didn't I just, before calling connect(), told it that the cross-domain-policy file is at port 80 of that server?



            Well, I'm tired + frustrated.


            Been reading a LOT about this domain-policies, mostly on Adobe's website/blogs. What can I say - so much CRAP I've never seen. "master policy", "meta policy" ,"policy" ,"policy" ,"policy" ,"policy" ,"policy".................... "the background of policies".......... bah!

            How can I enable a port?? A simple question. Cut the crap.



            ..... messiah!

            • 3. Re: An app using Socket is acting wierd.
              Lopo Nopo Level 1

              None to help out uh, surprising.

              Where are the designers of this system? Cafeteria?


              ... what a poor story..


              Let's hope Microsoft will take over quickly with Silverlight.