ssCore.UDP.setNotify

Tell SWF Studio about a UDP event that you'd like to receive notifications for.


Availability:

First available in version 3.0 build 2039.


Input Parameters:

event - The name of the event notification you want enabled. Valid values include: onReceive,onReceiveBinary,onReceiveError.


Output Parameters:

result - Notification data for the specified event (see description of events for more detail).


Asynchronous Mode:

When this method is called asynchronously, a return object containing the output parameters is passed to the specified callback function.

ssCore.UDP.setNotify( paramsObject [, callbackParamsObject] [, errorParamsObject] );


Synchronous Mode:

When this method is called synchronously, a return object containing the output parameters is returned to the caller immediately.

var returnObject = ssCore.UDP.setNotify( paramsObject );


Notes:

To cancel notifications about an event, use UDP.clearNotify.


Events:

name - onReceive
type - triggered
result - "sender IP address,message body"

When a message arrives successfully, an onReceive event will be triggered, and the data returned will be a string comprised of two pieces of information seperated by a comma: the sender's IP address, and the message body.

ssCore.App.setNotify({event:"onReceive"}, {callback:onDataReceived});

function onDataReceived(ret_obj, cb_obj, err_obj)
{
    if (ret_obj.success)
    {
        var v = ret_obj.result.split(",");
        ssDebug.trace("message receive from: " + v.shift());
        ssDebug.trace("message: " + v.join(","));
    }
}

name - onReceiveBinary
type - triggered
result - "sender IP address,message body (in hex string format)"

When a message arrives successfully, an onReceiveBinary event will be triggered, and the data returned will be a string comprised of two pieces of information seperated by a comma: the sender's IP address, and the message body in hex string format.

ssCore.App.setNotify({event:"onReceiveBinary"}, {callback:onBinaryDataReceived});

function onBinaryDataReceived(ret_obj, cb_obj, err_obj)
{
    if (ret_obj.success)
    {
        var v = ret_obj.result.split(",");
        ssDebug.trace("message receive from: " + v.shift());
        ssDebug.trace("message: " + v.join(","));
    }
}

name - onReceiveError
type - triggered
result - "errorMessage"

The onReceiveError event is triggered when there is an error. The errorMessage always consists of a 5 digit error code (a Winsock error number), a colon (':') and some text. Possible error codes include:

ssCore.App.setNotify({event:"onReceiveError"}, {callback:onUDPReceiveError});

function onUDPReceiveError(ret_obj, cb_obj, err_obj)
{
    if (ret_obj.success)
    {
        var v = ret_obj.result.split(":");
        ssDebug.trace("error code: " + Number(v.shift()));
        ssDebug.trace("description: " + v.join(":"));
    }
}