Atlas/XDHqDEMO.js
function pseudoServer_(createCallback, callbacks, head) {
	var client = new net.Socket();

	client.connect(pPort, pAddr, () => {
		let relaunch = true;

		client.write(handleString(token));

		if ( isTokenEmpty() ) {
			if (head === undefined)
				head = "";
			client.write(handleString(head));
		}

		client.on('readable', () => {
			if (client._xdhDOM === undefined) {
				let offset = 0;
				let query = getQuery(client);

				if (isTokenEmpty()) {
					[token, offset] = getString(query, offset);

					if (isTokenEmpty())
						throw getString(query, offset)[0];

					if (wPort != ":0") {
						let completeURL = "http://" + wAddr + wPort + "/" + cgi + ".php?_token=" + token;

						console.log(completeURL);
                        console.log(new Array(completeURL.length + 1).join('^'));
						console.log("Open above URL in a web browser. Enjoy!");

						open(completeURL);
					}
				} else {
					let returnedToken = "";

					[returnedToken, offset] = getString(query, offset);

					if (returnedToken == "")
						throw getString(query, offset)[0];

					if (returnedToken != token)
						throw "Unmatched token !!!";
				}

				client._xdhDOM = createCallback();
				client._xdhDOM._xdhSocket = client;
				client._xdhDOM._xdhIsDEMO = true;
				client._xdhDOM._xdhType = types.UNDEFINED;
				client.write(addString(addString(Buffer.from(""), mainProtocolLabel), mainProtocolVersion));
			} else if (relaunch) {
                let query = "";
				let offset = 0;
				let errorMessage = "";
				let notification = "";

				pseudoServer(createCallback, callbacks);	// Useless to give 'head', as it will no more be used.

				query = getQuery(client);

				[errorMessage, offset] = getString(query, offset);

				if (errorMessage != "")
					throw (errorMessage);

				[notification, offset] = getString(query, offset);

				if (notification != "")
					console.log(notification);

				getString(query, offset);	// Language.

				client.write(handleString("NJS"));

				relaunch = false;
			} else {
				let query;

				let cont = true;

				query = getQuery(client);

				if (client._xdhDOM._xdhType === types.UNDEFINED) {
					let id, action;

					id = getId(query);
					action = getAction(query);

					callbacks[action](client._xdhDOM, id);

					if (client._xdhDOM._xdhType === types.UNDEFINED) {
						cont = false;
						standBy(client);
					}  else
						cont = client._xdhDOM._xdhType === types.VOID;
				}

				while (cont) {
					if (client._xdhDOM._xdhCallback != undefined) {
						let type = client._xdhDOM._xdhType;
						client._xdhDOM._xdhType = types.UNDEFINED;
						if (type === types.VOID)
							client._xdhDOM._xdhCallback();
						else
							client._xdhDOM._xdhCallback(getResponse(query, type));

						if (client._xdhDOM._xdhType === types.UNDEFINED) {
							cont = false;
							standBy(client);
						} else if (client._xdhDOM._xdhType !== types.VOID)
							cont = false;
					} else {
						if (client._xdhDOM._xdhType !== types.VOID)
							getResponse(query, client._xdhDOM._xdhType);
						client._xdhDOM._xdhType = types.UNDEFINED;
						cont = false;
						standBy(client);
					}
				}
			}
		});
	});
	client.on('error', (err) => {
		throw "Unable to connect to '" + pAddr + ":" + pPort + "' !!!";
	});
}
function pseudoServer_(createCallback, callbacks, head) {
	var client = new net.Socket();

	client.connect(pPort, pAddr, () => {
		let relaunch = true;

		client.write(handleString(token));

		if ( isTokenEmpty() ) {
			if (head === undefined)
				head = "";
			client.write(handleString(head));
		}

		client.on('readable', () => {
			if (client._xdhDOM === undefined) {
				let offset = 0;
				let query = getQuery(client);

				if (isTokenEmpty()) {
					[token, offset] = getString(query, offset);

					if (isTokenEmpty())
						throw getString(query, offset)[0];

					if (wPort != ":0") {
						let completeURL = "http://" + wAddr + wPort + "/" + cgi + ".php?_token=" + token;

						console.log(completeURL);
                        console.log(new Array(completeURL.length + 1).join('^'));
						console.log("Open above URL in a web browser. Enjoy!");

						open(completeURL);
					}
				} else {
					let returnedToken = "";

					[returnedToken, offset] = getString(query, offset);

					if (returnedToken == "")
						throw getString(query, offset)[0];

					if (returnedToken != token)
						throw "Unmatched token !!!";
				}

				client._xdhDOM = createCallback();
				client._xdhDOM._xdhSocket = client;
				client._xdhDOM._xdhIsDEMO = true;
				client._xdhDOM._xdhType = types.UNDEFINED;
				client.write(addString(addString(Buffer.from(""), mainProtocolLabel), mainProtocolVersion));
			} else if (relaunch) {
                let query = "";
				let offset = 0;
				let errorMessage = "";
				let notification = "";

				pseudoServer(createCallback, callbacks);	// Useless to give 'head', as it will no more be used.

				query = getQuery(client);

				[errorMessage, offset] = getString(query, offset);

				if (errorMessage != "")
					throw (errorMessage);

				[notification, offset] = getString(query, offset);

				if (notification != "")
					console.log(notification);

				getString(query, offset);	// Language.

				client.write(handleString("NJS"));

				relaunch = false;
			} else {
				let query;

				let cont = true;

				query = getQuery(client);

				if (client._xdhDOM._xdhType === types.UNDEFINED) {
					let id, action;

					id = getId(query);
					action = getAction(query);

					callbacks[action](client._xdhDOM, id);

					if (client._xdhDOM._xdhType === types.UNDEFINED) {
						cont = false;
						standBy(client);
					}  else
						cont = client._xdhDOM._xdhType === types.VOID;
				}

				while (cont) {
					if (client._xdhDOM._xdhCallback != undefined) {
						let type = client._xdhDOM._xdhType;
						client._xdhDOM._xdhType = types.UNDEFINED;
						if (type === types.VOID)
							client._xdhDOM._xdhCallback();
						else
							client._xdhDOM._xdhCallback(getResponse(query, type));

						if (client._xdhDOM._xdhType === types.UNDEFINED) {
							cont = false;
							standBy(client);
						} else if (client._xdhDOM._xdhType !== types.VOID)
							cont = false;
					} else {
						if (client._xdhDOM._xdhType !== types.VOID)
							getResponse(query, client._xdhDOM._xdhType);
						client._xdhDOM._xdhType = types.UNDEFINED;
						cont = false;
						standBy(client);
					}
				}
			}
		});
	});
	client.on('error', (err) => {
		throw "Unable to connect to '" + pAddr + ":" + pPort + "' !!!";
	});
}
********** OLD !!! **********