This object allows you to establish a connection to a TCP server.
Constructor function.
var myObject = new Tcp(events);
var myObject = new Tcp();
var myObject = new Tcp({ onConnected: function() { Console.print("Connected!"); }, onDisconnected: function() { Console.print("Disconnected!"); } });
Opens a connection to a server.
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 server.
myObject.write(data);
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 event or the waitForBytesWritten method.
Writes some text to the server.
myObject.writeText(text);
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 event or the waitForBytesWritten method.
Closes a connection with a server.
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 server.
myObject.read();
To know when data is available use the onReadyRead event or the waitForReadyRead method.
Returns the text sent by the server.
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();
Freezes the execution until all data has been written or waitTime time elapsed.
myObject.waitForBytesWritten(waitTime);
myObject.waitForBytesWritten();
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 data sent to the server has been written.
myObject.onBytesWritten = function(bytes) {};
myObject.onBytesWritten = function(bytes) { //Event action };
Called when an error has occurred.
myObject.onError = function(errorMessage) {};
myObject.errorMessage = function(errorMessage) { //Event action };
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, Tcp.ReadOnly | Tcp.Unbuffered);