Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • EspaƱol
      • FranƧais
      • PortuguĆŖs
  • ę—„ęœ¬čŖžć‚³ćƒŸćƒ„ćƒ‹ćƒ†ć‚£
  • ķ•œźµ­ ģ»¤ė®¤ė‹ˆķ‹°
Locked
0

DatagramSocket, unable to bind socket on Android device

Guest
Apr 11, 2011 Apr 11, 2011

hi,

when I upload an apk to my Desire Z, with INTERNET manifest permissions added, I cannot  bind a socket  to its local network,

or connect it to a remote computer, because of an invalid socket eror:

Error #2002: Operation attempted on invalid socket.

I'm using air 2.5 and android 2.2. Also,

Also, should the findInterfaces method not return at least one interface? It returns 0.

public class UDPClient
    {
    
        protected var _datagramSocket: DatagramSocket = new DatagramSocket()
   
        public function UDPClient( )
        {
            findInterface();
            init();
        }
        public function findInterface():void {
            var results:Vector.<NetworkInterface> = NetworkInfo.networkInfo.findInterfaces();
            trace( "l: " + results.length );//RETURNS 0
 
        }
       
        protected function init():void
        {
          
            if( _datagramSocket.bound )
            {
                _datagramSocket.close();
                _datagramSocket = new DatagramSocket();
            }

               FAILS TO BIND OR CONNECT:
            _datagramSocket.bind( 33445, "127.0.0.1");//INVALID SOCKET ERROR

            // _datagramSocket.bind( 33445, "0.0.0.0");//INVALID SOCKET ERROR

          //_datagramSocket.connect( "77.250.160.80", 33443);//INVALID SOCKET ERROR

            _datagramSocket.addEventListener(DatagramSocketDataEvent.DATA, dataHandler)
            _datagramSocket.addEventListener(IOErrorEvent.IO_ERROR, IOErrorHandler);
            _datagramSocket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
            _datagramSocket.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
            _datagramSocket.receive();
        }

TOPICS
Development
4.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Apr 11, 2011 Apr 11, 2011

The Datagram socket class is not currently supported on mobile. (See http://help.adobe.com/en_US/air/build/WS144092a96ffef7cc16ddeea2126bb46b82f-8000.html)

Also note that you must add the following permissions to use the NetworkInfo class on Android:

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 29, 2011 Apr 29, 2011

Seriously, what's up with that. Can't create ServerSocket, Can't create DatagramSocket. No NetworkInfo. There's so many possibilities with those on the mobie platform and we can't have any of it.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 02, 2011 May 02, 2011
LATEST

thanks Joe.

So does this mean that we can't use UDP at all to send and receive messages  with air for android to and from remote computers?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines