User Tools

Site Tools


en:code:data:udp

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

en:code:data:udp [2011/10/02 00:29]
jmgr [readText]
en:code:data:udp [2016/10/09 11:10]
Line 1: Line 1:
-====== Udp ====== 
-This object allows you to establish a connection to an UDP peer. 
  
-===== Functions ===== 
- 
-==== Udp ==== 
-Constructor function. 
- 
-=== Syntax === 
-<code javascript>​ 
-var myObject = new Udp(events);​ 
-</​code>​ 
- 
-=== Arguments === 
-  - events - (object) the events that can be called 
-    * onConnected - ([[#​onConnected|onConnected]]) called when the object is connected to the peer 
-    * onDisconnected - ([[#​onDisconnected|onDisconnected]]) called when the object is disconnected from the peer 
-    * onReadyRead - ([[#​onReadyRead|onReadyRead]]) called when the object is ready to read data sent from the peer 
-    * onError - ([[#​onError|onError]]) called when an error has occured 
- 
-=== Example === 
-<code javascript>​ 
-var myObject = new Udp(); 
-</​code>​ 
-<code javascript>​ 
-var myObject = new Udp({ 
- onConnected:​ function() 
- { 
- Console.print("​Connected!"​);​ 
- }, 
- onDisconnected:​ function() 
- { 
- Console.print("​Disconnected!"​);​ 
- } 
-}); 
-</​code>​ 
- 
-===== Methods ===== 
- 
-==== connect ==== 
-Opens a connection to a peer. 
- 
-=== Syntax === 
-<code javascript>​ 
-myObject.connect(hostname,​ port, openMode); 
-</​code>​ 
-<code javascript>​ 
-myObject.connect(hostname,​ port); 
-</​code>​ 
- 
-=== Arguments === 
-  - hostname - (string) the hostname to connect to (ip address or dns) 
-  - port - (integer) the port number 
-  - openMode - (OpenMode) the open mode (default: read & write) 
- 
-=== Returns === 
-  * (Udp) this Udp 
- 
-=== Notes === 
-This method is asynchronous,​ this means that it will return before a connection is established. 
-To known when a connection is made use the [[#​onConnected|onConnected]] event or the [[#​waitForConnected|waitForConnected]] method. 
- 
-==== write ==== 
-Writes some data to the peer. 
- 
-=== Syntax === 
-<code javascript>​ 
-myObject.write(data);​ 
-</​code>​ 
- 
-=== Arguments === 
-  - data - (mixed) the data to write 
- 
-=== Returns === 
-  * (Udp) this Udp 
- 
-=== Notes === 
-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 known if the data has arrived. 
- 
-==== writeText ==== 
-Writes some text to the peer. 
- 
-=== Syntax === 
-<code javascript>​ 
-myObject.writeText(text);​ 
-</​code>​ 
- 
-=== Arguments === 
-  - text - (string) the text to write 
- 
-=== Returns === 
-  * (Udp) this Udp 
- 
-=== Notes === 
-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 known if the data has arrived. 
- 
-==== disconnect ==== 
-Closes a connection with a peer. 
- 
-=== Syntax === 
-<code javascript>​ 
-myObject.disconnect();​ 
-</​code>​ 
-<code javascript>​ 
-myObject.disconnect();​ 
-</​code>​ 
- 
-=== Returns === 
-  * (Udp) this Udp 
- 
-=== Notes === 
-This method is asynchronous,​ this means that it will return before the connection is closed. 
-To known when the connection is closed use the [[#​onDisconnected|onDisconnected]] event or the [[#​waitForDisconnected|waitForDisconnected]] method. 
- 
-==== read ==== 
-Returns the data sent by the peer. 
- 
-=== Syntax === 
-<code javascript>​ 
-myObject.read();​ 
-</​code>​ 
- 
-=== Returns === 
-  * (mixed) the data 
- 
-=== Notes === 
-To known when data is available use the [[#​onReadyRead|onReadyRead]] event or the [[#​waitForReadyRead|waitForReadyRead]] method. 
- 
-==== readText ==== 
-Returns the text sent by the peer. 
- 
-=== Syntax === 
-<code javascript>​ 
-myObject.readText(encoding);​ 
-</​code>​ 
-<code javascript>​ 
-myObject.readText();​ 
-</​code>​ 
- 
-=== Arguments === 
-  - encoding - ([[en:​code:​core:​global#​encoding|Encoding]]) the encoding to use 
- 
-=== Returns === 
-  * (string) the text 
- 
-=== Notes === 
-To known when text is available use the [[#​onReadyRead|onReadyRead]] event or the [[#​waitForReadyRead|waitForReadyRead]] method. 
- 
-==== waitForConnected ==== 
-Freezes the execution until a connection has been established or **waitTime** time elapsed. 
- 
-=== Syntax === 
-<code javascript>​ 
-myObject.waitForConnected(waitTime);​ 
-</​code>​ 
-<code javascript>​ 
-myObject.waitForConnected();​ 
-</​code>​ 
- 
-=== Arguments === 
-  - waitTime - (integer) the time to wait (milliseconds,​ default: 30000) 
- 
-=== Returns === 
-  * (Udp) this Udp 
- 
-=== Exceptions === 
-  * (ConnectionError) cannot establish a connection to the host 
- 
-==== waitForDisconnected ==== 
-Freezes the execution until the connection has been closed or **waitTime** time elapsed. 
- 
-=== Syntax === 
-<code javascript>​ 
-myObject.waitForDisconnected(waitTime);​ 
-</​code>​ 
-<code javascript>​ 
-myObject.waitForDisconnected();​ 
-</​code>​ 
- 
-=== Arguments === 
-  - waitTime - (integer) the time to wait (milliseconds,​ default: 30000) 
- 
-=== Returns === 
-  * (Udp) this Udp 
- 
-=== Exceptions === 
-  * (DisconnectionError) waiting for disconnection failed 
- 
-==== waitForReadyRead ==== 
-Freezes the execution until data is available or **waitTime** time elapsed. 
- 
-=== Syntax === 
-<code javascript>​ 
-myObject.waitForReadyRead(waitTime);​ 
-</​code>​ 
-<code javascript>​ 
-myObject.waitForReadyRead();​ 
-</​code>​ 
- 
-=== Arguments === 
-  - waitTime - (integer) the time to wait (milliseconds,​ default: 30000) 
- 
-=== Returns === 
-  * (Udp) this Udp 
- 
-=== Exceptions === 
-  * (ReadyReadError) waiting for ready read failed 
- 
-===== Events ===== 
- 
-==== onConnected ==== 
-Called when a connection is established. 
- 
-=== Syntax === 
-<code javascript>​ 
-myObject.onConnected = function() {}; 
-</​code>​ 
- 
-=== Example === 
-<code javascript>​ 
-myObject.onConnected = function() 
-{ 
- //Event action 
-}; 
-</​code>​ 
- 
-==== onDisconnected ==== 
-Called when a connection is closed. 
- 
-=== Syntax === 
-<code javascript>​ 
-myObject.onDisconnected = function() {}; 
-</​code>​ 
- 
-=== Example === 
-<code javascript>​ 
-myObject.onDisconnected = function() 
-{ 
- //Event action 
-}; 
-</​code>​ 
- 
-==== onReadyRead ==== 
-Called when data is available and can be read using the [[#​read|read]] method. 
- 
-=== Syntax === 
-<code javascript>​ 
-myObject.onReadyRead = function() {}; 
-</​code>​ 
- 
-=== Example === 
-<code javascript>​ 
-myObject.onReadyRead = function() 
-{ 
- //Event action 
-}; 
-</​code>​ 
- 
-==== onError ==== 
-Called when an error has occurred. 
- 
-=== Syntax === 
-<code javascript>​ 
-myObject.onError = function(errorMessage) {}; 
-</​code>​ 
- 
-=== Arguments === 
-  - errorMessage - (string) text describing the error 
- 
-=== Example === 
-<code javascript>​ 
-myObject.errorMessage = function(errorMessage) 
-{ 
- //Event action 
-}; 
-</​code>​ 
- 
-===== Enumerations ===== 
- 
-==== OpenMode ==== 
-Udp open mode. 
- 
-=== Values === 
-  - ReadOnly: socked opened for reading only 
-  - WriteOnly: socked opened for writing only 
-  - ReadWrite: socked opened for reading and writing 
-  - Unbuffered: socked opened in unbuffered mode 
- 
-=== Notes === 
-This is a flag enumeration,​ that means that you can use multiple values using the | operator. 
-Example: 
-<code javascript>​ 
-myObject.connect("​127.0.0.1",​ 80, Udp.ReadOnly | Udp.Unbuffered);​ 
-</​code>​ 
en/code/data/udp.txt ยท Last modified: 2016/10/09 11:10 (external edit)