udp

rcb. udp

new udp()

UDP interface functions
Source:
Example
var receive_port = 55047; // the listening port on this PC
var send_ip = "192.168.1.114"; // where to send the packet
var send_port = 64126; // on which port to send the packet

rcb.udp.init(receive_port, send_ip, send_port, UDPInitialized);

rcb.udp.onReceive(function UDPReceived(arrayBuffer){
    var message = rcb.udp.ab2str(arrayBuffer);
    rcb.console.print("Received: " + message);
});

function UDPInitialized(){
    var buffer = rcb.udp.str2ab("Hi from RCbenchmark script!");
    rcb.udp.send(buffer);
}

Methods

(static) ab2str(arrayBuffer) → {String}

Helper function that converts an ArrayBuffer Object to a string.
Parameters:
Name Type Description
arrayBuffer ArrauBuffer The buffer to convert.
Source:
Returns:
The string representation of the ArrayBuffer Object.
Type
String

(static) init(receivePort, SendIP, SendPort, callbackopt)

Create an UDP socket for external communication. Only one socket can be opened at a time.
Parameters:
Name Type Attributes Description
receivePort Integer The port to which the UDP packets will be received on this machine.
SendIP String The IP address of the receiver for the packets
SendPort Integer The port to send the packets to.
callback udpReady <optional>
The function to execute when the UDP socket is ready.
Source:

(static) onReceive(callback)

Calls the specified callback function when new data is received.
Parameters:
Name Type Description
callback UDPdataReceived The function to execute when the UDP message is sent.
Source:

(static) send(sendData, callbackopt)

Sends a packet to the IP/Port specified in the rcb.udp.init function.
Parameters:
Name Type Attributes Description
sendData ArrayBuffer The data to send. Use the str2ab helper function.
callback UDPsent <optional>
The function to execute when the UDP message is sent.
Source:

(static) str2ab(str) → {ArrayBuffer}

Helper function that converts a string into an ArrayBuffer Object.
Parameters:
Name Type Description
str String The string to convert.
Source:
Returns:
The ArrayBuffer Object, which can be sent to the UDP functions
Type
ArrayBuffer