en:code:data:tcp
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
code:data:tcp [2011/01/27 20:03] – [connect] jmgr | en:code:data:tcp [2013/06/13 07:18] – jmgr | ||
---|---|---|---|
Line 18: | Line 18: | ||
* onReadyRead - ([[# | * onReadyRead - ([[# | ||
* onBytesWritten - ([[# | * onBytesWritten - ([[# | ||
+ | * onError - ([[# | ||
=== Example === | === Example === | ||
Line 24: | Line 25: | ||
</ | </ | ||
<code javascript> | <code javascript> | ||
- | var myObject = new Sql({ | + | var myObject = new Tcp({ |
onConnected: | onConnected: | ||
{ | { | ||
- | Console.print(" | + | Console.print(" |
}, | }, | ||
onDisconnected: | onDisconnected: | ||
{ | { | ||
- | Console.print(" | + | Console.print(" |
} | } | ||
}); | }); | ||
Line 39: | Line 40: | ||
==== connect ==== | ==== connect ==== | ||
- | Opens a connection | + | Opens a connection to a server. |
=== Syntax === | === Syntax === | ||
Line 58: | Line 59: | ||
=== Notes === | === Notes === | ||
- | This function | + | This method |
- | To known when a connection is made use the [[# | + | To know when a connection is made use the [[# |
+ | |||
+ | ==== write ==== | ||
+ | Writes some data to the server. | ||
+ | |||
+ | === Syntax === | ||
+ | <code javascript> | ||
+ | myObject.write(data); | ||
+ | </ | ||
+ | |||
+ | === Arguments === | ||
+ | - data - (mixed) the data to write | ||
+ | |||
+ | === Returns === | ||
+ | * (Tcp) this Tcp | ||
+ | |||
+ | === Notes === | ||
+ | This method is asynchronous, | ||
+ | To know when the data has been sent use the [[# | ||
+ | |||
+ | ==== writeText ==== | ||
+ | Writes some text to the server. | ||
+ | |||
+ | === Syntax === | ||
+ | <code javascript> | ||
+ | myObject.writeText(text); | ||
+ | </ | ||
+ | |||
+ | === Arguments === | ||
+ | - text - (string) the text to write | ||
+ | |||
+ | === Returns === | ||
+ | * (Tcp) this Tcp | ||
+ | |||
+ | === Notes === | ||
+ | This method is asynchronous, | ||
+ | To know when the text has been sent use the [[# | ||
+ | |||
+ | ==== disconnect ==== | ||
+ | Closes a connection with a server. | ||
+ | |||
+ | === Syntax === | ||
+ | <code javascript> | ||
+ | myObject.disconnect(); | ||
+ | </ | ||
+ | <code javascript> | ||
+ | myObject.disconnect(); | ||
+ | </ | ||
+ | |||
+ | === Returns === | ||
+ | * (Tcp) this Tcp | ||
+ | |||
+ | === Notes === | ||
+ | This method is asynchronous, | ||
+ | To know when the connection is closed use the [[# | ||
+ | |||
+ | ==== read ==== | ||
+ | Returns the data sent by the server. | ||
+ | |||
+ | === Syntax === | ||
+ | <code javascript> | ||
+ | myObject.read(); | ||
+ | </ | ||
+ | |||
+ | === Returns === | ||
+ | * (mixed) the data | ||
+ | |||
+ | === Notes === | ||
+ | To know when data is available use the [[# | ||
+ | |||
+ | ==== readText ==== | ||
+ | Returns the text sent by the server. | ||
+ | |||
+ | === Syntax === | ||
+ | <code javascript> | ||
+ | myObject.readText(encoding); | ||
+ | </ | ||
+ | <code javascript> | ||
+ | myObject.readText(); | ||
+ | </ | ||
+ | |||
+ | === Arguments === | ||
+ | - encoding - ([[en: | ||
+ | |||
+ | === Returns === | ||
+ | * (string) the text | ||
+ | |||
+ | === Notes === | ||
+ | To know when text is available use the [[# | ||
+ | |||
+ | ==== waitForConnected ==== | ||
+ | Freezes the execution until a connection has been established or **waitTime** time elapsed. | ||
+ | |||
+ | === Syntax === | ||
+ | <code javascript> | ||
+ | myObject.waitForConnected(waitTime); | ||
+ | </ | ||
+ | <code javascript> | ||
+ | myObject.waitForConnected(); | ||
+ | </ | ||
+ | |||
+ | === Arguments === | ||
+ | - waitTime - (integer) the time to wait (milliseconds, | ||
+ | |||
+ | === 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 javascript> | ||
+ | myObject.waitForDisconnected(); | ||
+ | </ | ||
+ | |||
+ | === Arguments === | ||
+ | - waitTime - (integer) the time to wait (milliseconds, | ||
+ | |||
+ | === 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 javascript> | ||
+ | myObject.waitForReadyRead(); | ||
+ | </ | ||
+ | |||
+ | === Arguments === | ||
+ | - waitTime - (integer) the time to wait (milliseconds, | ||
+ | |||
+ | === 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 javascript> | ||
+ | myObject.waitForBytesWritten(); | ||
+ | </ | ||
+ | |||
+ | === Arguments === | ||
+ | - waitTime - (integer) the time to wait (milliseconds, | ||
+ | |||
+ | === 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 | ||
+ | }; | ||
+ | </ | ||
+ | |||
+ | ==== onError ==== | ||
+ | Called when an error has occurred. | ||
+ | |||
+ | === Syntax === | ||
+ | <code javascript> | ||
+ | myObject.onError = function(errorMessage) {}; | ||
+ | </ | ||
+ | |||
+ | === 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(" | + | myObject.connect(" |
</ | </ |
en/code/data/tcp.txt · Last modified: 2021/02/13 11:23 by 127.0.0.1