Skip to main content
Known Participant
January 18, 2014
Question

How to communicate between AIR desktop and AIR mobile applications using same WIFI network?

  • January 18, 2014
  • 1 reply
  • 1135 views

Hi,

I am creating a desktop AIR application and a mobile "helper" application running on iPad.

I would like to be able to send messages from the desktop app to the iPad app and vice versa. I have looked at different options but can't seem to get this to work.

Using AIR 3.8 I have tried:

- ServerSocket / socket => Able to setup the server socket on my desktop but the iPad can not connect to it (IO_ERROR)

- P2P: Using netconnection rtmfp but though both desktop and ipad successfully connect the members count for the netGroup is always 1 and I get no neighbour connected event.

How should I do this? Is it even possible?

If I click a button on my desktop app I would like the iPad app to respond by showing a URL which is passed.

Just spend hours on this without any luck. How to connect via the Wifi network without knowing any IP addresses?

Here is my desktop code:

private var server:ServerSocket;

                              private var connectedClients:Vector.<Socket> = new Vector.<Socket>;

                              private function createServer():void{

                                        server = new ServerSocket();

                                        server.addEventListener(ServerSocketConnectEvent.CONNECT, onConnect);

                                        server.bind(7934); // this is the number of the port where your socket communicate

                                        server.listen();

                              }

 

                              private function onConnect(e:ServerSocketConnectEvent):void{

  trace("connected");

                                        connectedClients.push(e.socket);

                                        trace(e.socket.connected);

                                        trace(e.socket.localAddress + " / " + e.socket.remoteAddress);

                              }

 

                              protected function application_initializeHandler(event:FlexEvent):void

                              {

                                        createServer();

                              }

And the iPad code:

private var socket:Socket;

  // on the client socket application you have to create the connection and then manage (send and receive) data from the server

                              private function createSocketConnection():void{

                                        socket = new Socket()

                                        socket.addEventListener(Event.CONNECT, connectedToServer);

                                        socket.addEventListener(ProgressEvent.SOCKET_DATA, receiveData);

                                        socket.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);

                                        socket.addEventListener(Event.CLOSE, closeSocket);

  //pass to connect method the server IP and the port to comunicate

                                        socket.connect("0.0.0.0", 7934);

                              }

                              protected function receiveData(event:ProgressEvent):void {

  // here you can read all the packets sent from the server

  trace("receiving data");

                              }

                              protected function ioErrorHandler(event:IOErrorEvent):void {

  trace("ioErrorHandler: " + event);

                              }

                              private function connectedToServer(e:Event):void{

  //yes! you are connected to the socket server

  trace("connected to server");

                              }

                              private function closeSocket(e:Event):void{

  //your socket connection is closed

  trace("connection is closed");

                              }

 

                              protected function application_initializeHandler(event:FlexEvent):void

                              {

                                        createSocketConnection();

                              }

 

If I start the desktop app nothing traces. If I then start the iPad app I get:

ioErrorHandler: [IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2031: Socket Error. URL: 0.0.0.0" errorID=2031]

This topic has been closed for replies.

1 reply

Known Participant
January 18, 2014

Also to note:

When I start the desktop app and in the browser I go to http://127.0.0.1:7934/ it traces

true

127.0.0.1 / 127.0.0.1

so that part is working. How come iPad can't connect?

Known Participant
January 18, 2014

Changing the 0.0.0.0 to 127.0.0.1 doesn't work either =>

ioErrorHandler: [IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2031: Socket Error. URL: 127.0.0.1" errorID=2031]

I'm running in debug mode (fast packaging)

User Unknow
Legend
January 18, 2014

dont enter 127.0.0.1 anywhere. Its loopback url. Use 0.0.0.0 instead.

Also be sure that your firewall on desktop is disabled for fast testing purpose.

In my case I spent few hours and was like crazy monkey. Than typed ipad local ip to desktop firewall with selected port and this worsk.

I can use tcp or udp without any issues