This object allows you to establish a connection to an UDP peer.
Constructor function.
var myObject = new Udp(events);
var myObject = new Udp();
var myObject = new Udp({ onConnected: function() { Console.print("Connected!"); }, onDisconnected: function() { Console.print("Disconnected!"); } });
Opens a connection to a peer.
myObject.connect(hostname, port, openMode);
myObject.connect(hostname, port);
This method is asynchronous, this means that it will return before a connection is established. To know when a connection is made use the onConnected event or the waitForConnected method.
Writes some data to the peer.
myObject.write(data);
This method is asynchronous, this means that it will return before the data has been written. Due to the unreliable nature of UDP you have no means to know if the data has arrived.
Writes some text to the peer.
myObject.writeText(text);
This method is asynchronous, this means that it will return before the data has been written. Due to the unreliable nature of UDP you have no means to know if the data has arrived.
Closes a connection with a peer.
myObject.disconnect();
myObject.disconnect();
This method is asynchronous, this means that it will return before the connection is closed. To know when the connection is closed use the onDisconnected event or the waitForDisconnected method.
Returns the data sent by the peer.
myObject.read();
To know when data is available use the onReadyRead event or the waitForReadyRead method.
Returns the text sent by the peer.
myObject.readText(encoding);
myObject.readText();
To know when text is available use the onReadyRead event or the waitForReadyRead method.
Freezes the execution until a connection has been established or waitTime time elapsed.
myObject.waitForConnected(waitTime);
myObject.waitForConnected();
Freezes the execution until the connection has been closed or waitTime time elapsed.
myObject.waitForDisconnected(waitTime);
myObject.waitForDisconnected();
Freezes the execution until data is available or waitTime time elapsed.
myObject.waitForReadyRead(waitTime);
myObject.waitForReadyRead();
Called when a connection is established.
myObject.onConnected = function() {};
myObject.onConnected = function() { //Event action };
Called when a connection is closed.
myObject.onDisconnected = function() {};
myObject.onDisconnected = function() { //Event action };
Called when data is available and can be read using the read method.
myObject.onReadyRead = function() {};
myObject.onReadyRead = function() { //Event action };
Called when an error has occurred.
myObject.onError = function(errorMessage) {};
myObject.errorMessage = function(errorMessage) { //Event action };
Udp open mode.
This is a flag enumeration, that means that you can use multiple values using the | operator. Example:
myObject.connect("127.0.0.1", 80, Udp.ReadOnly | Udp.Unbuffered);