5 Replies Latest reply on Mar 18, 2010 9:41 AM by victor.turansky

    Sockets not working in v4 Beta for me

    pjc158

      I am using version 4 Beta and have written a simple flex client that uses the socket class to connect to a local .NET Socket Server.

      I can connect to the .NET server but cannot send any data.

       

      I get no errors or exceptions when running the program.

       

      I have a policy server running locally which does not seem get a request from the flex client even though I have the following statement before a connection request;

       

      Security.loadPolicyFile("xmlsocket://10.75.63.237:843")

      var sock:Socket = new Socket();

      sock.connect("10.75.63.237", 4444);

      sock.writeBytes(buf, noBytes);

      sock.flush();

      sock.close();

       

      I have written both a .NET and Java client and the work fine with the .NET Socket Server.

       

      Has anybody experience problems with Sockets?

        • 1. Re: Sockets not working in v4 Beta for me
          victor.turansky Level 1

          You must  listen Event.CONNECT event of socket, because  only when socket is connected  you  can send something

           

          private function connect():void     {

               var sock:Socket = new Socket();

               sock.addEventListener(Event.CONNECT, onConnect);

               sock.connect("10.75.63.237",  4444);

          }

           

          private function onConnect(e:Event):void     {

               sock.writeBytes(buf, noBytes);

               sock.flush();

               sock.close();

          }

          • 2. Re: Sockets not working in v4 Beta for me
            pjc158 Level 1

            The code provided still does not work.

             

            Additional information the flex app is being built as an air app.

            • 3. Re: Sockets not working in v4 Beta for me
              victor.turansky Level 1

              private function connect():void     {

                   var sock:Socket =  new Socket();

                   sock.addEventListener(Event.CONNECT,  onConnect);

                   sock.connect("10.75.63.237",  4444);

              }

               

              private  function onConnect(e:Event):void     {

                   var sock:Socket = Socket(e.target);

                   sock.writeBytes(buf,  noBytes);

                   sock.flush();

                   sock.close();

              }

               

              May be problem not in the socket.

              And listen error events SecurityEvent.SECURITY_ERROR and IOErrorEvent.IO_ERROR.

              Usually it is Security Error.

              Try this code!

              • 4. Re: Sockets not working in v4 Beta for me
                pjc158 Level 1

                I have tried the alternative code suggested and it still does not work.

                 

                Also I but a break point in the onConnect() function setup using sock.addEventListener(Event.CONNECT,  onConnect) and it never gets called even though I see the connection made in the .NET server.

                 

                Could it be a 4.0 Beta issue?

                • 5. Re: Sockets not working in v4 Beta for me
                  victor.turansky Level 1

                  I worked with Sockets in Flash Builder 4 beta 2 and they worked well!

                   

                  What about errors?

                  Did you listen errors in your application?

                  Use try - catch block when you use socket.connect()

                  And what about crossdomain on your server?

                  Could you show your full code?