无法将 AIR 应用程序连接到 socket.io

发布于 2024-12-08 16:05:09 字数 2905 浏览 0 评论 0原文

我正在尝试将 AIR 应用程序连接到 socket.io,但它不起作用。 这是我的代码:

<?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"
                       creationComplete="creationCompleteHandler(event)">

    <s:layout>
        <s:VerticalLayout />
    </s:layout>

    <fx:Script>
        <![CDATA[
            import com.pnwrain.flashsocket.FlashSocket;
            import com.pnwrain.flashsocket.events.FlashSocketEvent;

            import mx.events.FlexEvent;

            protected var socket:FlashSocket;


            protected function creationCompleteHandler(event:FlexEvent):void
            {
                trace("Connect");
                socket = new FlashSocket("ws://mydomain.com:8080/socketFolder/");
                socket.addEventListener(FlashSocketEvent.CONNECT, onConnect);
                socket.addEventListener(FlashSocketEvent.MESSAGE, onMessage);
                socket.addEventListener(FlashSocketEvent.CLOSE, onDisconnect);
                socket.addEventListener(FlashSocketEvent.IO_ERROR, onIOError);
                socket.addEventListener(FlashSocketEvent.SECURITY_ERROR, onSecurityError);
            }
            protected function onConnect(event:FlashSocketEvent):void{
                trace("connect");
            }
            protected function onDisconnect(event:FlashSocketEvent):void{
                trace("disconnect");
            }
            protected function onIOError(event:FlashSocketEvent):void{
                trace("onIOError");
            }
            protected function onSecurityError(event:FlashSocketEvent):void{
                trace("onSecurityError");
            }
            protected function onMessage(event:FlashSocketEvent):void{
                trace("onMessage");
            }
        ]]>
    </fx:Script>

</s:WindowedApplication>

如您所见,我正在使用 FlashSocket。

我的服务器配置是:

io.configure( function(){
    io.enable('browser client minification');  // send minified client
    io.enable('browser client etag');          // apply etag caching logic based on version number
    io.enable('browser client gzip');          // gzip the file
    io.disable('destroy upgrade');
    io.set('log level', 3);
    io.set('transports', [
        'websocket'
      , 'flashsocket'
      , 'htmlfile'
      , 'xhr-polling'
      , 'jsonp-polling'
      ]);
});

我在服务器控制台中收到“销毁非socket.io升级”,因此我添加了io.disable('destroy Upgrade');。我不再收到消息,但没有帮助。

在 AIR 应用程序中,我没有收到任何错误,任何事件侦听器都被调用。

socket.io 服务器运行正常,因为我有一个 HTML 客户端连接到它。 该服务器是远程服务器,而不是本地主机。

我必须设置任何安全策略吗?我正在从 Flash Builder 运行 AIR 应用程序。

任何想法将不胜感激。

I'm trying to connect an AIR application to socket.io, it's just not working.
This is my 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"
                       creationComplete="creationCompleteHandler(event)">

    <s:layout>
        <s:VerticalLayout />
    </s:layout>

    <fx:Script>
        <![CDATA[
            import com.pnwrain.flashsocket.FlashSocket;
            import com.pnwrain.flashsocket.events.FlashSocketEvent;

            import mx.events.FlexEvent;

            protected var socket:FlashSocket;


            protected function creationCompleteHandler(event:FlexEvent):void
            {
                trace("Connect");
                socket = new FlashSocket("ws://mydomain.com:8080/socketFolder/");
                socket.addEventListener(FlashSocketEvent.CONNECT, onConnect);
                socket.addEventListener(FlashSocketEvent.MESSAGE, onMessage);
                socket.addEventListener(FlashSocketEvent.CLOSE, onDisconnect);
                socket.addEventListener(FlashSocketEvent.IO_ERROR, onIOError);
                socket.addEventListener(FlashSocketEvent.SECURITY_ERROR, onSecurityError);
            }
            protected function onConnect(event:FlashSocketEvent):void{
                trace("connect");
            }
            protected function onDisconnect(event:FlashSocketEvent):void{
                trace("disconnect");
            }
            protected function onIOError(event:FlashSocketEvent):void{
                trace("onIOError");
            }
            protected function onSecurityError(event:FlashSocketEvent):void{
                trace("onSecurityError");
            }
            protected function onMessage(event:FlashSocketEvent):void{
                trace("onMessage");
            }
        ]]>
    </fx:Script>

</s:WindowedApplication>

As you can see I'm using FlashSocket.

My server configuration is:

io.configure( function(){
    io.enable('browser client minification');  // send minified client
    io.enable('browser client etag');          // apply etag caching logic based on version number
    io.enable('browser client gzip');          // gzip the file
    io.disable('destroy upgrade');
    io.set('log level', 3);
    io.set('transports', [
        'websocket'
      , 'flashsocket'
      , 'htmlfile'
      , 'xhr-polling'
      , 'jsonp-polling'
      ]);
});

I was receiving "destroying non-socket.io upgrade" in the server console, so I added io.disable('destroy upgrade');. I no longer get the message, but didn't help.

In the AIR app, I dont get any error, any of the event listeners is been called.

The socket.io server is running correctly, since I have an HTML client connected to it.
The server is a remote server, not localhost.

Do I have to setup any security policy? I'm running the AIR app from Flash Builder.

Any ideas will be appreciated.

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

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

发布评论

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

评论(1

謌踐踏愛綪 2024-12-15 16:05:09

如果您使用的是 FlashSocket.io 0.7.x 标记的下载,那么您只需在新服务器行中指定主机和端口。

socket = new FlashSocket("mydomain.com:8080");

试一试,看看是否能更进一步。

模拟

If you are using the FlashSocket.io 0.7.x tagged downloads then you should only have to specify the host and port in the new server line.

socket = new FlashSocket("mydomain.com:8080");

Give that a shot and see if you get any further.

sim

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