en:code:data:tcp
This is an old revision of the document!
Table of Contents
Tcp
This object allows you to establish a connection to a TCP server.
Functions
Tcp
Constructor function.
Syntax
var myObject = new Tcp(events);
Arguments
- events - (object) the events that can be called
- onConnected - (onConnected) called when the object is connected to the server
- onDisconnected - (onDisconnected) called when the object is disconnected from the server
- onReadyRead - (onReadyRead) called when the object is ready to read data sent from the server
- onBytesWritten - (onBytesWritten) called when the object has finished writing data to the server
Example
var myObject = new Tcp();
var myObject = new Sql({ onConnected: function() { Console.print("Connected !"); }, onDisconnected: function() { Console.print("Disconnected !"); } });
Methods
connect
Opens a connection with a server.
Syntax
myObject.connect(hostname, port, openMode);
myObject.connect(hostname, port);
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
- (Tcp) this Tcp
Notes
This function is asynchronous, this means that this function will return before a connection is established. To known when a connection is made use the onConnected event or the waitForConnected method.
Events
onConnected
Called when a connection is established.
Syntax
myObject.onConnected = function() {};
Example
myObject.onConnected = function() { //Event action };
onDisconnected
Called when a connection is closed.
Syntax
myObject.onDisconnected = function() {};
Example
myObject.onDisconnected = function() { //Event action };
onReadyRead
Called when data is available and can be read using the read method.
Syntax
myObject.onReadyRead = function() {};
Example
myObject.onReadyRead = function() { //Event action };
onBytesWritten
Called when data sent to the server has been written.
Syntax
myObject.onBytesWritten = function(bytes) {};
Arguments
- bytes - (integer) the number of bytes that have been written
Example
myObject.onBytesWritten = function(bytes) { //Event action };
Enumerations
OpenMode
File 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:
myObject.connect("127.0.0.1", 80, File.ReadOnly | File.Unbuffered);
en/code/data/tcp.1296158576.txt.gz · Last modified: 2021/02/13 11:23 (external edit)