Drivers/Connectors
You can connect to Trueno from your favorite programming language. Currently supported languages are:
- Javascript/Node.js
- Java
- Python
Examples
javascript
java
python
/* require if in node */
const Trueno = require('trueno-javascript-driver');
/* create driver instance */
let trueno = new Trueno({host: 'http://localhost', port: 8000});
/* connecting to trueno backend */
trueno.connect((s)=> {
/* connected, s is a socket */
console.log('connected', s.id);
}, ()=> {
/* disconnected from trueno backend */
console.log('disconnected');
});
package mypackage;
import org.trueno.driver.lib.core.Trueno;
public class MyClass {
private static Trueno trueno = new Trueno();
public static void main(String[] args) {
//Using Java 8 Lambdas
trueno.connect(
connSocket -> System.out.println("Connected: " + connSocket.id()),
discSocket -> System.out.println("Disconnected" + discSocket.id()));
}
}
# Two ways to connect using the Python driver:
# 1. Automatic connection
from trueno_python_driver import Trueno
trueno = Trueno(host='http://localhost', port=8000)
#May use 'with'
with Trueno(host='http://localhost', port=8000) as trueno:
if trueno.connected():
#Do work
#######
# 2. Manual connection (can define callbacks)
from trueno_python_driver import Trueno
def conn_callback(*args):
print('Connected')
def disc_callback(*args):
print('Disconnected')
trueno = Trueno(host='http://localhost', port=8000, auto_connect=False)
trueno.connect(conn_callback, disc_callback)