ssCore.TCP.setNotify

Tell SWF Studio about a TCP 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: onConnect,onDisconnect,onReceive,onReceiveBinary,onReceiveError,onSendError.


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.TCP.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.TCP.setNotify( paramsObject );


Notes:

To cancel notifications about any of the above events, use TCP.clearNotify.


Events:

name - onConnect
type - triggered
result - "destinationAddress"

The onConnect event is triggered when the socket connects. This happens either as the result of a successful call to TCP.open or a client connecting to a listening socket (see TCP.listen). The network name or IP address (of the destination) is passed to the event handler.

ssCore.TCP.setNotify({event:"onConnect"}, {callback:onTCPConnect});

function onTCPConnect(ret_obj, cb_obj, err_obj)
{
    if (ret_obj.success)
    {
        ssDebug.trace("socket to '" + ret_obj.result + "' is connected.");
    }
}

name - onDisconnect
type - triggered
result - "message"

The onDisconnect event is triggered when the socket is closed. The message "Connection closed." is passed to the event handler.

ssCore.TCP.setNotify({event:"onDisconnect"}, {callback:onTCPDiconnect});

function onTCPDisconnect(ret_obj, cb_obj, err_obj)
{
    if (ret_obj.success)
    {
        ssDebug.trace("the socket was closed.");
    }
}

name - onReceive
type - triggered
result - "messageData"

The onReceive event is triggered when a message arrives successfully. The messageData is passed to the event handler.

ssCore.TCP.setNotify({event:"onReceive"}, {callback:onTCPReceive});

function onTCPReceive(ret_obj, cb_obj, err_obj)
{
    if (ret_obj.success)
    {
        ssDebug.trace("message received: " + ret_obj.result);
    }
}

name - onReceiveBinary
type - triggered
result - "messageData (in hex string format)"

The onReceiveBinary event is triggered when a message arrives successfully. The messageData is passed to the event handler.

ssCore.TCP.setNotify({event:"onReceiveBinary"}, {callback:onTCPReceiveBinary});

function onTCPReceiveBinary(ret_obj, cb_obj, err_obj)
{
    if (ret_obj.success)
    {
        ssDebug.trace("message received: " + ret_obj.result);
    }
}

name - onReceiveError
type - triggered
result - "errorMessage"

The onReceiveError event is triggered when there is an error receiving a message. A short description containing an error code is passed to the event handler. When using TCP.close the following error is generated: "10053: Error receiving a message." This indicates that the connection was closed by the client software.

ssCore.TCP.setNotify({event:"onReceiveError"}, {callback:onTCPReceiveError});

function onTCPReceiveError(ret_obj, cb_obj, err_obj)
{
    if (ret_obj.success)
    {
        ssDebug.trace("error receiving data: " + ret_obj.result);
    }
}

Note: When using TCP.close the following error is generated: "10053: Error receiving a message." This indicates that the connection was closed by the client software.

name - onSendError
type - triggered
result - "errorMessage"

The onSendError event is triggered when there is an error sending a message. A short description containing an error code is passed to the event handler.

ssCore.TCP.setNotify({event:"onSendError"}, {callback:onTCPSendError});

function onTCPSendError(ret_obj, cb_obj, err_obj)
{
    if (ret_obj.success)
    {
        ssDebug.trace("error sending data: " + ret_obj.result);
    }
}