Quantcast
Channel: Adobe Community : Unanswered Discussions - AIR Development
Viewing all articles
Browse latest Browse all 2010

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

$
0
0

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:

 

privatevar server:ServerSocket;

                              privatevar connectedClients:Vector.<Socket> = new Vector.<Socket>;

                              privatefunction 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();

                              }

 

                              privatefunction onConnect(e:ServerSocketConnectEvent):void{

  trace("connected");

                                        connectedClients.push(e.socket);

                                        trace(e.socket.connected);

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

                              }

 

                              protectedfunction application_initializeHandler(event:FlexEvent):void

                              {

                                        createServer();

                              }

 

 

And the iPad code:

 

privatevar socket:Socket;

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

                              privatefunction 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);

                              }

                              protectedfunction receiveData(event:ProgressEvent):void {

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

  trace("receiving data");

                              }

                              protectedfunction ioErrorHandler(event:IOErrorEvent):void {

  trace("ioErrorHandler: " + event);

                              }

                              privatefunction connectedToServer(e:Event):void{

  //yes! you are connected to the socket server

  trace("connected to server");

                              }

                              privatefunction closeSocket(e:Event):void{

  //your socket connection is closed

  trace("connection is closed");

                              }

 

                              protectedfunction 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]


Viewing all articles
Browse latest Browse all 2010

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>