_server.sendResponse()

Availability:

SmartFoxServer PRO 1.2.1

Usage:

_server.sendResponse(response, fromRoom, sender, recipients, type)

Description:

Send a message to a client or list of clients using the default XML format or a raw, string-based format.

Properties:

response   An object containing all properties and objects that you want to send to the client(s). On the client side you will obtain the same exact object.
As a convention there should be always a property called _cmd containing the name of the action being performed.

If you use the raw/string protocol, you will have to pass an Array of parameters instead of an object. (Check the example below)
fromRoom   (optional) The roomId from where this message is coming. If you don't need it, just set it to -1
sender   (optional) The User object that you want to pass as the sender of this message. If you don't need this just use null
recipients   an Array containing one ore more User objects
type   (optional) By default it is set to "xml", and the message will be XML formatted. You can also specify "str" if you wish to send a raw, string based message.

Returns:

Nothing

Example:

This example shows how to send some game status data to a list of clients:

/*
* Sending some game status data to the clients
*/ 

var responseObj = {}
responseObj._cmd = "status"
responseObj.score = 1500
responseObj.energy = 30
responseObj.ammo = {laser:100, ringLaser:50, nuclearBeam:40}

// "type" is not specified, we'll use XML protocol
_server.sendResponse(responseObj, -1, null, userList)

This example shows how to send some game status data to a list of clients using raw/string protocol:

/*
* Sending some game status data to the clients
*/ 

var responseObj = []
responseObj.push("status") // 1st element is the command name
responseObj.push(1500)
responseObj.push(30)
responseObj.push(100)
responseObj.push(50)
responseObj.push(40)

// type is set to "str", we'll user raw/string protocol
_server.sendResponse(responseObj, -1, null, userList, "str")

Note:

See also: