package com.odp.odpcloud;
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.util.concurrent.Callable;
import javax.net.SocketFactory;
import javax.net.ssl.SSLSocketFactory;
import anywheresoftware.b4a.*;
import anywheresoftware.b4a.BA.*;
@ShortName("odp_Cloud")
@Version(0.1f)
@Author("Lee D. Gillie, CCP")
@Events( values = {
"connected(Success as Boolean)"
})
public class CloudConsumer {
private BA ba;
private String eventName;
private boolean connected;
private Socket socket;
private String transport;
CloudConsumer() {
connected = false;
socket = null;
transport = null;
}
public void Initialize(BA ba, String EventName ) {
this.ba = ba;
this.eventName = EventName.toLowerCase(BA.cul);
}
public void connect(final String Hostname, final int Port, final int TimeoutMilliseconds) {
BA.runAsync(ba, this, eventName + "_connected", new Object[] {false}, new Callable<Object[]>() {
@Override
public Object[] call() throws Exception {
socket = new Socket();
try {
InetAddress Address = InetAddress.getByName(Hostname);
InetSocketAddress i = new InetSocketAddress(Address, Port);
BA.Log("CloudConsumer connecting to " + Hostname + ":" + Integer.toString(Port));
socket.connect(i, TimeoutMilliseconds);
connected = true;
BA.Log("CloudConsumer connected.");