© 2014 Samsung Electronics Co., Ltd. All rightsreserved.
Learning how to exchange string data with peer agents is a basic SAP management skill:
/* SAAgent object has been obtained using the requestSAAgent() method */ var SASocket; var connectioncallback = { /* Connection between provider and consumer is established */ onconnect: function(socket) { SASocket = socket; for (var i = 0; i < SAAgent.channelId.length; i++) { SASocket.sendData(SAAgent.channelIds[i], "send message to " + i + "th channel."); } } } SAAgent.setServiceConnectionListener(connectioncallback);
To send an encrypted string message to a remote accessory peer agent, use the sendSecureData() method instead of the sendData() method:
SASocket.sendSecureData(SAAgent.channelIds[i], "send message to " + i + "th channel.");
function onreceive(channelId, data) { console.log("Message received - " + channelId + " : " + data); } SASocket.setDataReceiveListener(onreceive);