server Class Ape.sockClient

Summary

Extends:
SocketClient object (TCP client)
File
<./src/Ape_Server/modules/libape-spidermonkey.c>

sockClient Class Detail

Ape.sockClient (port, host, options)
Ape.sockClient is a class constructor.

SockClient is used to connect to a socket server.

File:
<./src/Ape_Server/modules/libape-spidermonkey.c>
Parameters:
{integer|string} port
{string} host
hostname or ip-address
{object} options Optional
{boolean} options.flushlf Optional Default: false
If true onRead is called only when a "\n" is received (data is split around it)
Returns:
Examples
//Instantiating a socket client is simple
var socket = new Ape.sockClient('21', 'example.com', {flushlf: true} );
var socket = new Ape.sockClient('21', 'example.com', {flushlf: true});
socket.onConnect = function() {
	Ape.log("Connected to example.com");
	this.write("Hello\n");
}
//"\n" are removed.
socket.onRead = function(data) {
	Ape.log("Data : " + data);
}
socket.onDisconnect = function() {
	Ape.log("Gone !");
}
See:

Summary

Own
Attributes Name Description
<static>   Ape.sockClient. onAccept (socketServer) Trigger a event if a clientSocket is connected to a serverSocket.
<static>   Ape.sockClient. onConnect () Trigger a event if a connection has been established.
<static>   Ape.sockClient. onDisconnect () Trigger a event if the server closes a connection to this socketClient.
<static>   Ape.sockClient. onRead (data) Trigger a event if something is read on a clientSocket.
Inherrited

<static> {void} Ape.sockClient. onAccept (socketServer)

Trigger a event if a clientSocket is connected to a serverSocket.
Parameters:
{sockServer} socketServer Optional
Returns:
{void}
Example
socket.onAccept = function(server) {
	Ape.log("New server !");
	server.write("Hello world\n");
}
See:

<static> {void} Ape.sockClient. onConnect ()

Trigger a event if a connection has been established.
Returns:
{void}
Example
socket.onConnect = function() {
	Ape.log("We are connected !");
	this.write("Hello\n");
}
See:
Ape.sockClient
Ape.sockServer
Ape.sockClient.accept
Ape.sockServer.accept

<static> {void} Ape.sockClient. onDisconnect ()

Trigger a event if the server closes a connection to this socketClient.
Returns:
{void}
Example
socket.onDisconnect = function() {
	Ape.log("Gone !");
}
See:

<static> {void} Ape.sockClient. onRead (data)

Trigger a event if something is read on a clientSocket. This function is called when a server sends data on his socket.
Parameters:
{string} data The data string that has been read
Returns:
{void}
Example
socket.onDisconnect = function() {
	Ape.log("Gone !");
}
See: