Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Adobe AIR Development

Reply
Contributor
Posts: 19
Registered: ‎04-11-2010
My Device: Curve

Simple Socket Question / Error...

[ Edited ]

I'm testing out a socket connection for an RDP app on the playbook.

 

Flash Builder Burrito 4.5

Adobe AIR SDK 2.5 Hero

Playbook SDK 0.9.2

Playbook Sim 0.9.2

VMPlayer running in Bridged Networking mode

 

 

public function RDPApp()
		{
			var socket:Socket = new Socket();
			socket.addEventListener(Event.CONNECT, onConnect);
			socket.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
			socket.addEventListener(Event.CLOSE, onClose);
			socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecurityError);
			socket.addEventListener(ProgressEvent.SOCKET_DATA, onReceivedData);
			socket.connect("http://www.google.com", 80);
			socket.close();
			
			stage.nativeWindow.visible = true;
		}
		
		
		private function closeWindow(event:MouseEvent):void{
			stage.nativeWindow.close();
		}
		
		protected function onConnect(event:Event):void
		{
			// TODO Auto-generated method stub
		}
		
		protected function onIOError(event:IOErrorEvent):void
		{
			trace(event);
		}
		
		protected function onClose(event:Event):void
		{
			// TODO Auto-generated method stub
		}
		
		protected function onSecurityError(event:SecurityErrorEvent):void
		{
			// TODO Auto-generated method stub
		}
		
		protected function onReceivedData(event:ProgressEvent):void
		{
			// TODO Auto-generated method stub
		}

 

 

The code above throws on the sim and on the desktop:

 

IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2031: Socket Error. URL: http://www.google.com" errorID=2031]

 

Googling this error message indicates that the client flash app has not received the required policy file from the server.

 

I was under the impression that AIR apps running on the desktop sandbox (Playbook included) do not require the retrieval of the policy file.

 

Any help is much appreciated.

 

Matt

 

 

Developer
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10

Re: Simple Socket Question / Error...

In doing a Google search, I see people have this problem due to some issue from the server (in creating FTP clients).  Some said it has to do with dedicated vs shared IP addresses.  Try using one of the IP addresses to google.com instead of dealing with potential DNS issues.

 

Also, have you tried using URLLoader instead?

Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10

Re: Simple Socket Question / Error...

Socket addresses generally do not include the protocol/scheme, as in "http://".  Try just using a host name or numeric IP address (still as a String).


Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Contributor
Posts: 19
Registered: ‎04-11-2010
My Device: Curve

Re: Simple Socket Question / Error...

I've tried IP addresses, host names, fully qualified domain names, invalid ip addresses (0.0.0.0) and no dice.

 

Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10

Re: Simple Socket Question / Error...

You might have tried those things, but only the unadorned host name or IP address is going to work.

 

Also, why are you closing the socket as soon as you issue the connect request?

 

A simple test here shows that a socket opened properly to www.google.com on port 80, with a raw "GET" request issued, connects and returns a response.  (I'm getting a "400 Bad Request" response from Google, but that's a different story.  The socket does connect properly.)


Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Contributor
Posts: 19
Registered: ‎04-11-2010
My Device: Curve

Re: Simple Socket Question / Error...

URLLoader() does work in that I can retrieve the html from google's website.  

 

Maybe URLLoader() has a different level of security?

 

Unfortunately URLLoader() will not work for my app as I would need a socket connection for my app.

Contributor
Posts: 19
Registered: ‎04-11-2010
My Device: Curve

Re: Simple Socket Question / Error...

It was the immediate socket.close() call that was tripping me up.

 

There is something strange going on as I had set breakpoints in the IOError and the onClose event handlers and I never hit the onClose event handler just the IOError.

 

Could use a more descriptive error message ("trying to connect with closed socket blah blah") but I'm happy to be able to continue.


Thanks for your help.