2

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?

angryip
  • 2,140
  • 5
  • 33
  • 67
  • 2
    You may be getting no responses to this because it's hard for people to understand why a "simulated real-like version of a backend server" is a useful thing to have. If you're trying to create a proxy server in java, there are probably easier ways to do that (google "java proxy socket server"). It's unlikely you can "act as an actual server that can perform some actions" without knowledge of Unidata internals. Finally, if you just want to see some log information about the traffic from client to server, google "Unidata serverdebug" and you can see queries and calls to subroutines/parameter – Ian McGowan Oct 03 '17 at 18:24
  • @IanMcGowan agreed. I'll crack the nut when i get some time under my belt. I decompiled all the jars and started playing around, but your reccomendations will help out. Thanks Ian! – angryip Oct 04 '17 at 04:18
  • @angryip, It has been more than a year that this thread is raised. Did you find a way or workaround for creating a fake server for UniData? – Barsham Mar 08 '18 at 02:55
  • 1
    @Barsham i never found a way to create a "simulated" unidata server. However, i did manage to use asjava to rewrite some components of the unidata api, so that i can "point" to something else as opposed to a socket connection. i.e sub.call(); method above would have been modified by asJava to point to jdbc queries for example, instead of a unidata server. – angryip Mar 09 '18 at 12:40

0 Answers0