I am looking at the following documentation in hopes of understanding uniData. The problem that I am experiencing is that I am unable to make a "simulated real-like version" of a backend server inorder to test my unidata queries.
Here is what I have so far:
I have a main entry into the server, to listen:
public static void main(final String[] args) throws UnknownHostException, IOException {
int clientNumber = 0;
final ServerSocket listener = new ServerSocket(31438);
try {
while (true) {
new MySimulatedConnection(listener.accept(), clientNumber++).start();
}
} finally {
listener.close();
}
}
The SimulatedConnection receives requests, and attempts to read some data from them. (Purely using sockets)
@Override
public void run() {
try {
final BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
final PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
while (true) {
final String input = in.readLine();
if (input == null || input.equals(".")) {
break;
}
out.print("## received message " + input);
}
} catch (final IOException e) {
System.out.println("Error handling client# " + requestNumber + ": " + e.getMessage());
} finally {
try {
socket.close();
} catch (final IOException e) {
System.out.println("## cant close socket " + e.getMessage());
}
}
}
On my client, I am establishing a uniData session with something like this:
public static void main(final String[] args) throws UnknownHostException, IOException, UniSubroutineException,
UniSessionException {
final FakeClient faker = new FakeClient();
faker.createConnection();
}
private void createConnection() throws UnknownHostException, IOException, UniSubroutineException,
UniSessionException {
System.out.println("Connecting to unidata...");
UniSession uSession = new UniSession();
final UniJava uj = new UniJava();
uSession = uj.openSession();
uSession.setHostName("127.0.0.1");
uSession.setUserName("sample_username");
uSession.setPassword("sample_password");
uSession.setAccountPath("some_account");
uSession.setTimeout(5000);
final int port = uSession.connection.getPort();
System.out.println("Testing connection to " + SERVER_ADDRESS + " on port " + port + "...");
final Socket testSocket = new Socket(SERVER_ADDRESS, port);
if (testSocket.isConnected()) {
System.out.println("Connection successful");
uSession.connect();
System.out.println("## we performed the connect");
final UniSubroutine sub = uSession.subroutine("UNIJAVA.SETUP", 3);
sub.setArg(0, "unknwon host");
sub.call();
System.out.println("## sub called");
} else {
System.out.println("### no connection possbile!");
}
}
Why am I doing it the way I am?
Well, I am experimenting to see how I can create a server and how I can query for some data out of it. Obviously, my first choice is to use socketing as this seems to be the basic principle of communication here.
What is working, and what is not?
So far, the client is able to connect to the tcp socket, and read this line:
System.out.println("Connection successful");
However, connecting using uniApi, yeilds no success and a long timeout (since that is the way i configured it in the uSession.setTimeout(5000); value :
uSession.connect();
In addition, my buffered reader reads no data on the server, as I am guessing the subroutine paramaters I am passing are actually not being called as strings.
With that in mind, what am I trying to do?
I want to update my server to accept uniAPI requests, and act as an actual server that can perform some actions. However, it is obvious that I am missing in implementing possibly some interface, or some connection management, inorder to get this to work. Any idea as to what that may be?