MentDB, The digital brain.  About me Home

Back / Clients

Connect with the Editor
Execute mental script with the REST API (method = POST or GET)
Java API
Web Socket API

Connect with the Editor

MentDB_Editor/osx-linux(windows)/bin/editor.sh(bat)

host: localhost
port: 9999
user: admin
password: pwd

Connect with 'admin' user, and type stop {id} to stop the server (Only user in 'system' group).

               

Execute mental script with the REST API (method = POST or GET)

http://localhost:9999/api-rest/?token=&script=&var1=&var2=


The user and the mental script must be into the same group, and the user must be in the 'api-rest' group.

Java API

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) {

      }

    }

  }

Web Socket API

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();




© 2012-2017 - Jimmitry Payet.