Nadia
Nadia

Reputation: 257

as3-websocket-server, how to manage the results

I downloaded the library as3-websocket-server ( https://github.com/childoftv/as3-websocket-server ) for a desktop air app and I'm trying to manage the results.

I'm using Flash professional, so I import the code by:

import com.childoftv.websockets.WebSocketServer;

Than I'm able to run the server by:

var sock:WebSocketServer = new WebSocketServer();
sock.attemptBind(8087,"127.0.0.1");

It works fine with an html5 client on any browser (I see it adding some trace in the .as file). But how can I manage the data I get from the browser directly in the main FLA file?

Instructions say to see WebSocketServerBasic.as but it neither works: I get error on invalid number of arguments (max1) calling the function WebSocketServerBasic.

So I'm using the main WebSocketServer.as But I don't find any code to manage the results... I should need something like:

sock.onMessageReceived (do something with the message...) 

or some addEventListener...

Any suggestion?

Thanks!

Upvotes: 0

Views: 632

Answers (1)

Organis
Organis

Reputation: 7316

I never worked with WSS, but just looking at it makes it something like that:

import com.childoftv.websockets.WebSocketServer;
import com.childoftv.websockets.events.ClientEvent;

var sock:WebSocketServer = new WebSocketServer();
sock.addEventListener(ClientEvent.CLIENT_MESSAGE_EVENT, handleMessage);
sock.attemptBind(8087, "127.0.0.1");

function handleMessage(e:ClientEvent):void
{
    trace(e.msg);
}

Upvotes: 1

Related Questions