开发者

Socket class is not working on Flex SDK 4.5

开发者 https://www.devze.com 2023-03-09 09:50 出处:网络
I am migrating an application from flex sdk 3.4 to flex sdk 4.5. I am using a telnet example of AS3 tutorials as base to construct a generic socket class that implement a specific protocol.

I am migrating an application from flex sdk 3.4 to flex sdk 4.5.

I am using a telnet example of AS3 tutorials as base to construct a generic socket class that implement a specific protocol.

The main problem is that the new application with the validated socket class does not fire any event (no error - no connected - no data - nothing). The try catch with the connect method does not throw any error. I checked if the events were successfully connected, but they are not fired never.

Update: I used the suggestions to modidy the code. Actually, now I am receiving an error on the security policy.

This is the constructor:

         public function GenericSocket(server:String, port:int, output:TextArea) {
            // set class variables to the values passed to the constructor.
            serverURL = server;
            portNumber = port;
            ta = output;

            // Create a new Socket object and assign event listeners.
            socket = new Socket();
            socket.addEventListener(Event.CONNECT, connectHandler);
            socket.addEventListener(Event.CLOSE, closeHandler);
            socket.addEventListener(ErrorEvent.ERROR, errorHandler);
            socket.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
                    //Added by suggestions
                    socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
            socket.addEventListener(ProgressEvent.SOCKET_DATA, dataHandler);

            // Load policy file from remote server.
            Security.loadPolicyFile("http://" + serverURL + "/crossdomain.xml");
            // Attempt to connect to remote socket server.
            tr开发者_JAVA百科y {
                msg("Trying to connect to " + serverURL + ":" + portNumber + "\n");
                socket.connect(serverURL, portNumber);
            } catch (error:Error) {
                /*
                Unable to connect to remote server, display error 
                message and close connection.
                */
                msg(error.message + "\n");
                socket.close();
            }
        }

This is the connectHandler, securityErrorHandler and the ioErrorHandler (Never called Update: Security handler is beign called)

        private function connectHandler(event:Event):void {
            if (socket.connected) {
                msg("connected...\n");
            } else {
                msg("Error: unable to connect\n");
            }
        }

//Added by suggestions

private function securityErrorHandler(event:SecurityErrorEvent):void {
            msg("securityErrorHandler: " + event+"\n");
        }

        public function ioErrorHandler(event:IOErrorEvent):void {
            msg("Error: Unable to connect: socket error.\n");
        }

Some idea or directive could be useful. Maybe some test to try the generic socket? maybe the type of the application?

Update: The error that I received is:

securityErrorHandler: [SecurityErrorEvent type="securityError" bubbles=false cancelable=false eventPhase=2 text="Error #2048"]

I am using these includes in the project:

           xmlns:mx="http://www.adobe.com/2006/mxml" 
           xmlns:s="library://ns.adobe.com/flex/spark"
           xmlns:mx2="library://ns.adobe.com/flex/mx"


Here you can find an answer I gave some time ago to the same problem you have. Be sure to read the comments and follow the links, there is a good example/tutorial on one of the links. It's basically related to the way you serve the security policy, you have to serve it via socket after the app has sent a request for it on port 843. For this, you need of course a sever app, can't be served by a the webserver via HTTP.

0

精彩评论

暂无评论...
验证码 换一张
取 消