server Class Ape.sockServer

Summary

Extends:
sockServer Object (TCP connection server)
File
<./src/Ape_Server/modules/libape-spidermonkey.c>

sockServer Class Detail

Ape.sockServer (port, ip, options)
Ape.sockServer is a class constructor.

SockServer is used to create a socket server that can accept client sockets,

File:
<./src/Ape_Server/modules/libape-spidermonkey.c>
Parameters:
{integer|string} port
{string} ip
The ip address to bind the server
{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 server that listens to port 80
var socket = new Ape.sockServer('80', '0.0.0.0', {flushlf: true} );
var socket = new Ape.sockServer('80', '0.0.0.0', {flushlf: true});
socket.onAccept = function(client) {
	Ape.log('New client !');
	client.write('Hello world\n');
}
socket.onRead = function(client, data) {
	Ape.log('Received data:' + data);
	if(data == 'bye') {
		client.close();
	}
}
See:

Summary

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

<static> {void} Ape.sockServer. onAccept (socketClient)

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

<static> {void} Ape.sockServer. 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:

<static> {void} Ape.sockServer. onDisconnect (client)

Trigger a event if the client is disconnected.
Parameters:
{sockClient} client Optional The client that has disconnected
Returns:
{void}
Example
client.onDisconnect = function() {
	Ape.log("Gone !");
}
See:

<static> {void} Ape.sockServer. onRead (client, data)

Trigger a event if something is read on a serverSocket. This function is called when a client sends data on his socket.
Parameters:
{sockClient} client Optional The client that send the data
{string} data Optional The data string that has been read
Returns:
{void}
Example
socket.onRead = function(client, data) {
	Ape.log('Received: ' + data);
}
See: