NetConnection and remoting in BlazeDS/LCDS

Normally, people use RemoteObject to talk to a remoting destination in BlazeDS which is a class part of Flex framework but once in a while, I get questions on whether it’s possible to do remoting with Flash’s NetConnection directly. Although using NetConnection has no immediate benefits, it’s helpful in case one does not want to use Flex framework or simply prefer using NetConnection.

Thanks to LegacyFilter in BlazeDS, this is indeed possible. Here’s an outline of what you need to do. First, create a NetConnection and connect to the URL of the endpoint you need to connect (which is defined in services-config.xml)

var nc:NetConnection = new NetConnection();
nc.connect("http://localhost:8400/team/messagebroker/amf" );

Then, do the NetConnection call with a special parameter, result/fault responders, and arguments to the remoting method. "remoting_AMF.echo", new Responder( resultHandler, faultHandler ), "hello");

The first parameter is important, the format is destinationId and method name seperated by a dot. In this example, we’re asking BlazeDS to direct the request to destination with id “remoting_AMF” and the “echo” method of the class that the destination exposes. LegacyFilter handles the rest. A full example is here in BlazeDS source tree.

14 thoughts on “NetConnection and remoting in BlazeDS/LCDS

  1. Once the NetConnection#call is invoked on the client side, LegacyFilter transforms that call on the server side into a RemotingMessage for RemotingService to handle.

  2. hey, thanks for the help

    I’m up and running, I can return a string, but how do I return a custom object? flex had a way of “automagically” casting custom objects (and arrays of custom objects) that were defined in java and had AS3 counterparts.

    so, a single string comes back ok, then I tried a java.util.List of strings and I got error #2173 (“unable to read object in stream”)

    I figured I’d get lists>arrays going, then try for custom objects


  3. sorry, I put xml in there and it disappeared

    my question was on how to configure the serialization switches for a channel. I want to have java collections map to as3 arrays, and I believe if I can set that in services-config.xml, but I cant figure out exactly how. what I get from the docs is:


    but it doesnt seem to do anything



  4. ooops, sorry, wasnt cycling tomcat between changes, just reloading context. looks like I can map java Collections to As3 arrays now, which is probably going to solve my first problem, a few posts back. thanks anyway!

  5. I am in the process of converting application over to Railo from CF. The application use flash remoting provided by the CF server.

    I have followed your post and I am having problems connecting to my server object, (cfc ruining on Railo)

    I have a the following destination id set up.


    And I am running the as3 code below

    var nc:NetConnection = new NetConnection();
    nc.connect(“http://xxxxxxx/flex2gateway” ); “testCF.process”, new Responder( onResult, onFault ), “hello”);

    function onResult(responder:Object):void {


    function onFault(responder:Object):void {
    var i=0;
    for (i in responder) {

    But I get the following error.

    [object Object]
    flex.messaging.MessageException: java.lang.NullPointerException : null

    Any help would be very much appreciated,


    1. You’re getting NullPointerException on the server. I’d check the server logs to get more details on the NullPointerException.

  6. The only benefit is that if you use NetConnection, you’re sticking with Flash only APIs, whereas RemoteObject needs Flex APIs and need rpc.swc in your application. I don’t think there’s any other benefit in terms of performance etc.

  7. Hi,

    I have been trying to figure out one simple question.
    Can I do multiple calls on the same gateway?
    I mean, let say I call a method “getItemDetails” and waiting its response, but before I get the response, call another one or the same?

    We use amfphp right now, but we are seriously looking at the java environment to use in the future.

    Another big question to me is the real meaning of netConnection.connect. Does it just store the gateway url or does it really tries to call the server for the first time?
    I have seen some examples, when they always initiate a new netConnection just to call one method and get response – I don’t think it is the right approach.


  8. Hi Benjamin,

    I think you should be able to submit multiple NetConnection calls.

    I don’t recall whether NetConnection#connect makes an actual connect. I seem to remember that NetConnection#connect simply sets things up on the client, and then NetConnection#call makes the actual request.

  9. Is it possible to use the default flex2gateway endpoint with the NetConnection?

    We are having an issue with ROs and blaze duplicate sessions, and saw moving to NetConnection as a possible solution. However, I am unable to get the base case working to the default flex gateway and remote-object-y ways of passing the RO call location.
    EX (the below always returns a fault, with the services-config on the server only having the default setup for flex2gateway):
    private function init():void {
    connection = new NetConnection(“”);

    private function fireRequest():void {“webservices.ApplicationSubfolder.ComponentName.getFunctionName”,
    new Responder(resultHandler, faultHandler),
    private function resultHandler(result:Object):void
    ta.text += “Server responded: “+ ObjectUtil.toString(result) + “\n”;
    private function faultHandler(fault:Object):void
    ta.text += “Received fault: ” + ObjectUtil.toString(fault) + “\n”;

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s