public static void main(String[] args) {
//Initialization
MentDBConnector connector = null;
//Try to connect and execute MQL queries
try {
//Server connection (9998 is the database port)
connector = new MentDBConnector("localhost", 9998, 10000, 10000);
//User connection
if (connector.connect("admin", "pwd")) {
//Display connection information
System.out.println(connector.serverConnectionState);
System.out.println(connector.clientConnectionState);
try {
//Execute a MQL query
System.out.println(connector.execute("who"));
//Execute another MQL query
System.out.println(connector.execute("sessions"));
} catch (Exception e) {
//Exception
System.out.println(e.getMessage());
}
} else {
//Display connection information
System.out.println(connector.serverConnectionState);
System.out.println(connector.clientConnectionState);
}
} catch (Exception e) {
//A connection error was generated
System.out.println(e.getMessage());
} finally {
try {
//Close the connector
connector.close();
} catch (Exception e) {
}
}
}
function init() {
MentDBWebSocket();
}
function MentDBWebSocket() {
websocket = new WebSocket("ws://localhost:9999/mentdb/");
websocket.onopen = function(evt) { onOpen(evt) };
websocket.onclose = function(evt) { onClose(evt) };
websocket.onmessage = function(evt) { onMessage(evt) };
websocket.onerror = function(evt) { onError(evt) };
}
function onOpen(evt) {
websocket.send("#login \"admin\" \"pwd\"");
}
function onClose(evt) {
}
function onMessage(evt) {
//alert(evt.data);
var obj = JSON.parse(evt.data);
}
function onError(evt) {
}
function disconnect() {
websocket.send("bye");
}
function chatMode() {
websocket.send("#j8i9m0m5i5t3r2y1p9a6y4e5t%");
}
function mqlMode() {
websocket.send("#j8i9m0m5i5t3r2y1p9a6y4e5t$");
}
init();