User Tools

Site Tools


en:code:data:tcp

This is an old revision of the document!


Tcp

This object allows you to establish a connection to a TCP server.

Functions

Tcp

Constructor function.

Syntax

var myObject = new Tcp(events);

Arguments

  1. 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

  1. hostname - (string) the hostname to connect to (ip address or dns)
  2. port - (integer) the port number
  3. 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.

Enumerations

OpenMode

File open mode.

Values

  1. ReadOnly: socked opened for reading only
  2. WriteOnly: socked opened for writing only
  3. ReadWrite: socked opened for reading and writing
  4. 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.1296157650.txt.gz · Last modified: 2020/02/09 13:26 (external edit)