Home » Docs » Server »
 

sockServer

(since 1.0)



A server socket class

Description


sockServer

Ape.sockServer is a class constructor. SockServer is used to create socker server that can accept clients sockets.

Parameters


port
The port on wich to listen

ip
The up on wich to bind the server

options
  • flushlf - (bool) ; defaults to : false If true, onRead is called only when a "\n" is received (data is split around it)

Examples


//Here we create a server that listen on all ips on 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();
	}
}

User notes


# No comment

Post a note


User notes may be edited or deleted, and usually a note is deleted because of the following reasons:
  • Bugs: Instead report a bug
  • Missing documentation: report that as a bug.
  • Support questions: See the community for available options.

In other words, do not ask questions within the user notes.

Note <b>,<u>,<i> HTML tags are allowed in the posts and the note formatting is preserved. URLs will be turned into clickable links, JavaScipt and C code blocks enclosed in the <source="javascript">JS Code</source> and <source="c">C Code</source> tags will be source highlighted automatically.