Socket 类不适用于 Flex SDK 4.5

发布于 2024-11-11 06:59:45 字数 2912 浏览 0 评论 0原文

我正在将应用程序从 flex sdk 3.4 迁移到 flex sdk 4.5。

我使用 AS3 教程的 telnet 示例作为基础来构造实现特定协议的通用套接字类。

主要问题是具有经过验证的套接字类的新应用程序不会触发任何事件(无错误 - 无连接 - 无数据 - 无)。使用 connect 方法进行 try catch 不会引发任何错误。我检查了事件是否已成功连接,但它们从未被触发。

更新:我使用了建议来修改代码。实际上,现在我收到了安全策略错误。

这是构造函数:

         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.
            try {
                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();
            }
        }

这是 connectHandler、securityErrorHandler 和 ioErrorHandler(从未调用更新:调用安全处理程序)

        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");
        }

一些想法或指令可能有用。也许进行一些测试来尝试通用套接字?也许是应用程序的类型?

更新: 我收到的错误是:

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

我在项目中使用这些包含:

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

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.
            try {
                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"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

轮廓§ 2024-11-18 06:59:45

在这里您可以找到我给出的答案前段时间你遇到了同样的问题。请务必阅读评论并点击链接,其中一个链接上有一个很好的示例/教程。它基本上与您提供安全策略的方式有关,在应用程序在端口 843 上发送请求后,您必须通过套接字提供服务。 为此,您当然需要一个服务器应用程序,不能由通过 HTTP 的网络服务器。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文