oscarm
oscarm

Reputation: 2650

Cant connect AIR app to socket.io

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.

Upvotes: 0

Views: 1387

Answers (1)

Simeon Bateman
Simeon Bateman

Reputation: 11

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

Upvotes: 1

Related Questions