User Tools

Site Tools


en:code:data:tcp

Differences

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

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
en:code:data:tcp [2011/01/27 20:03]
jmgr [connect]
en:code:data:tcp [2020/02/09 13:26] (current)
Line 18: Line 18:
     * onReadyRead - ([[#​onReadyRead|onReadyRead]]) called when the object is ready to read data sent from the server     * onReadyRead - ([[#​onReadyRead|onReadyRead]]) called when the object is ready to read data sent from the server
     * onBytesWritten - ([[#​onBytesWritten|onBytesWritten]]) called when the object has finished writing data to the server     * onBytesWritten - ([[#​onBytesWritten|onBytesWritten]]) called when the object has finished writing data to the server
 +    * onError - ([[#​onError|onError]]) called when an error has occured
  
 === Example === === Example ===
Line 24: Line 25:
 </​code>​ </​code>​
 <code javascript>​ <code javascript>​
-var myObject = new Sql({+var myObject = new Tcp({
  onConnected:​ function()  onConnected:​ function()
  {  {
- Console.print("​Connected !");+ Console.print("​Connected!"​);​
  },  },
  onDisconnected:​ function()  onDisconnected:​ function()
  {  {
- Console.print("​Disconnected !");+ Console.print("​Disconnected!"​);​
  }  }
 }); });
Line 39: Line 40:
  
 ==== connect ==== ==== connect ====
-Opens a connection ​with to server.+Opens a connection to server.
  
 === Syntax === === Syntax ===
Line 58: Line 59:
  
 === Notes === === Notes ===
-This function ​is asynchronous,​ this means that this function ​will return before a connection is established. +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.+To know when a connection is made use the [[#​onConnected|onConnected]] event or the [[#​waitForConnected|waitForConnected]] method. 
 + 
 +==== write ==== 
 +Writes some data to the server. 
 + 
 +=== Syntax === 
 +<code javascript>​ 
 +myObject.write(data);​ 
 +</​code>​ 
 + 
 +=== Arguments === 
 +  - data - (mixed) the data to write 
 + 
 +=== Returns === 
 +  * (Tcp) this Tcp 
 + 
 +=== Notes === 
 +This method is asynchronous,​ this means that it will return before the data has been written. 
 +To know when the data has been sent use the [[#​onBytesWritten|onBytesWritten]] event or the [[#​waitForBytesWritten|waitForBytesWritten]] method. 
 + 
 +==== writeText ==== 
 +Writes some text to the server. 
 + 
 +=== Syntax === 
 +<code javascript>​ 
 +myObject.writeText(text);​ 
 +</​code>​ 
 + 
 +=== Arguments === 
 +  - text - (string) the text to write 
 + 
 +=== Returns === 
 +  * (Tcp) this Tcp 
 + 
 +=== Notes === 
 +This method is asynchronous,​ this means that it will return before the data has been written. 
 +To know when the text has been sent use the [[#​onBytesWritten|onBytesWritten]] event or the [[#​waitForBytesWritten|waitForBytesWritten]] method. 
 + 
 +==== disconnect ==== 
 +Closes a connection with a server. 
 + 
 +=== Syntax === 
 +<code javascript>​ 
 +myObject.disconnect();​ 
 +</​code>​ 
 +<code javascript>​ 
 +myObject.disconnect();​ 
 +</​code>​ 
 + 
 +=== Returns === 
 +  * (Tcp) this Tcp 
 + 
 +=== Notes === 
 +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|onDisconnected]] event or the [[#​waitForDisconnected|waitForDisconnected]] method. 
 + 
 +==== read ==== 
 +Returns the data sent by the server. 
 + 
 +=== Syntax === 
 +<code javascript>​ 
 +myObject.read();​ 
 +</​code>​ 
 + 
 +=== Returns === 
 +  * (mixed) the data 
 + 
 +=== Notes === 
 +To know when data is available use the [[#​onReadyRead|onReadyRead]] event or the [[#​waitForReadyRead|waitForReadyRead]] method. 
 + 
 +==== readText ==== 
 +Returns the text sent by the server. 
 + 
 +=== 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 know 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 === 
 +  * (Tcp) this Tcp 
 + 
 +=== 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 === 
 +  * (Tcp) this Tcp 
 + 
 +=== 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 === 
 +  * (Tcp) this Tcp 
 + 
 +=== Exceptions === 
 +  * (ReadyReadError) waiting for ready read failed 
 + 
 +==== waitForBytesWritten ==== 
 +Freezes the execution until all data has been written or **waitTime** time elapsed. 
 + 
 +=== Syntax === 
 +<code javascript>​ 
 +myObject.waitForBytesWritten(waitTime);​ 
 +</​code>​ 
 +<code javascript>​ 
 +myObject.waitForBytesWritten();​ 
 +</​code>​ 
 + 
 +=== Arguments === 
 +  - waitTime - (integer) the time to wait (milliseconds,​ default: 30000) 
 + 
 +=== Returns === 
 +  * (Tcp) this Tcp 
 + 
 +=== Exceptions === 
 +  * (BytesWrittenError) waiting for bytes written failed
  
 ===== Events ===== ===== Events =====
Line 125: Line 294:
 <code javascript>​ <code javascript>​
 myObject.onBytesWritten = function(bytes) myObject.onBytesWritten = function(bytes)
 +{
 + //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  //Event action
Line 133: Line 321:
  
 ==== OpenMode ==== ==== OpenMode ====
-File open mode.+Open mode.
  
 === Values === === Values ===
Line 145: Line 333:
 Example: Example:
 <code javascript>​ <code javascript>​
-myObject.connect("​127.0.0.1",​ 80, File.ReadOnly | File.Unbuffered);​+myObject.connect("​127.0.0.1",​ 80, Tcp.ReadOnly | Tcp.Unbuffered);​
 </​code>​ </​code>​
en/code/data/tcp.1296158615.txt.gz · Last modified: 2020/02/09 13:26 (external edit)