0

I am using FlashSocket on my client side to make calls to socket.io on node.js server.

But i want specific values and function references to be available in the socket event listeners.

One approach that came to my mind was to pass the required values along with the request and make the server to send those parameters back along with the data. But that doesn't seem to help since I need the function handlers to be returned as well with the result.

The way i am doing it with http request is:

var token:AsyncToken = _service.send(item.params);
token.id = _tokenId;
token.params = item.params;
token.handler = item.resultHandler; // this would be called later in result or fault event handlers.

Is there a way to achieve this in flex sockets?

Thanks in advance.

Sarita
  • 837
  • 11
  • 19

1 Answers1

0

You could use AsyncResponder class and anonymous functions.

var token:AsyncToken = _service.send(item.params);
token.addResponder(new AsyncResponder(
    function(event:Object, token:Object = null):void {
        // result handler, it has access to item.params, etc.
    },
    function(error:FaultEvent, token:Object = null):void {
        // fault handler, it has access to item.params, etc.
    }  
));
Petr Hrehorovsky
  • 1,153
  • 2
  • 14
  • 16
  • But what would be stored in token? `var token:AsyncToken = socket.send({data: parameters},"message");` doesn't work. I want that the item.params to be accessible in the result handler like we have when we use asyncToken with httpService. – Sarita Nov 19 '13 at 13:25
  • The `var token:AsyncToken = _service.send(item.params);` is for HttpService. And i want this type of functionality for sockets. Are there any alternatives to be used with sockets? – Sarita Nov 20 '13 at 04:58
  • Sockets work differently. But you can use anonymous functions as listeners. – Petr Hrehorovsky Nov 20 '13 at 09:22