从 Actionscript 3 AIR 应用程序连接到 Socket 服务器

发布于 2024-11-07 07:17:49 字数 1358 浏览 1 评论 0原文

我通读了连接到套接字服务器的方法: http ://livedocs.adobe.com/flex/3/html/help.html?content=17_Networking_and_communications_5.html

我编写了一个 AIR 应用程序来连接到 java 服务器代码,但是客户端无法连接。代码中缺少什么?

<?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" backgroundColor="#D5F8C3">

    <fx:Script>
        <![CDATA[

            import flash.net.XMLSocket;



            var socket:XMLSocket;

            public function b1_clickHandler(event:MouseEvent):void
            {

                var socket:XMLSocket;
                socket.connect("127.0.0.1",8080);
                socket.send("Hello");
                //socket.addEventListener(DataEvent.DATA, onData);

            }




        ]]>
    </fx:Script>

    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->


    </fx:Declarations>
    <s:Button id="b1" x="285" y="162" label="Send Text" width="201" height="105" click="b1_clickHandler(event)"/>
</s:WindowedApplication>

I read through the method to connect to a socket server : http://livedocs.adobe.com/flex/3/html/help.html?content=17_Networking_and_communications_5.html

I wrote an AIR application to connect to the java server code, but the client cannot connect. What is missing in the code?

<?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" backgroundColor="#D5F8C3">

    <fx:Script>
        <![CDATA[

            import flash.net.XMLSocket;



            var socket:XMLSocket;

            public function b1_clickHandler(event:MouseEvent):void
            {

                var socket:XMLSocket;
                socket.connect("127.0.0.1",8080);
                socket.send("Hello");
                //socket.addEventListener(DataEvent.DATA, onData);

            }




        ]]>
    </fx:Script>

    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->


    </fx:Declarations>
    <s:Button id="b1" x="285" y="162" label="Send Text" width="201" height="105" click="b1_clickHandler(event)"/>
</s:WindowedApplication>

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

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

发布评论

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

评论(1

音盲 2024-11-14 07:17:49

在发送数据之前,您必须等待 CONNECTED 事件。另外,请确保您已管理跨域安全性(请参阅:http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b90204-7c60.html#WS5b3ccc516d4fbf351e63e3d118a9b90204-7c63

服务器/客户端代码: Air 2 ServerSocket 跨域问题

You have to wait for CONNECTED event before sending data. Also, be sure you've managed crossdomain security (look at : http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b90204-7c60.html#WS5b3ccc516d4fbf351e63e3d118a9b90204-7c63)

Server/client code exemple : Air 2 ServerSocket Crossdomain problem

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