Skip to main content
Participant
November 30, 2011
Question

Sockets

  • November 30, 2011
  • 1 reply
  • 498 views

Hi,

I'm trying to establish a socket connection to the remote server with an mobile application written in flash builder. I'm using flex 4.5 sdk.

While running the code in mobile emulators, the socket connection is working. But after deploying the application to the phone, I get an #2031 error.

the source code is the following:

<?xml version="1.0" encoding="utf-8"?>

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"

               xmlns:s="library://ns.adobe.com/flex/spark">

 

  <fx:Style>

    @11909012 s "library://ns.adobe.com/flex/spark";

   

    global {

      fontSize: 32;     

    }

  </fx:Style>

 

  <s:layout>

    <s:VerticalLayout horizontalAlign="center" paddingTop="20"/>

  </s:layout>

 

  <s:TextInput id="t" text="test test"/>

 

  <s:Button label="create notification">

    <s:click>

      <![CDATA[

      var s:Socket = new Socket();

      s.connect("serverName", 9999);

      s.addEventListener(Event.CONNECT, function(event:Event):void {

      trace('connected!');

      t.text = "connected";

      (event.currentTarget as Socket).writeInt(1);

      (event.currentTarget as Socket).writeUTF(t.text);

      (event.currentTarget as Socket).flush();

      (event.currentTarget as Socket).close();

      });

      s.addEventListener(IOErrorEvent.IO_ERROR, function(event:IOErrorEvent):void {

      trace('error! ' + event.errorID);

      t.text = "error! " + event.errorID;

      });

      s.addEventListener(ProgressEvent.SOCKET_DATA, function(event:ProgressEvent):void {

      trace('progress ');

      });

      ]]>

    </s:click>

  </s:Button>

 

</s:Application>

What am I doing wrong here?

This topic has been closed for replies.

1 reply

Innovatology
Participating Frequently
December 1, 2011

On mobile platforms, the app needs to request access to the internet, and the user needs to grant that permission on installation. How to request permission depends on the platform...

The old method (for Android and IOS):

http://help.adobe.com/en_US/air/build/WSfffb011ac560372f-5d0f4f25128cc9cd0cb-7ffe.html

The new method (for BlackBerry PlayBook):

http://docs.blackberry.com/en/developers/deliverables/23959/Overview_1352483_11.jsp#Accessing_secure_APIs_1524628_11