2

If I run following java class, no exception or error message occures, but I'm sure that connection cannot be established (GrailsApplication1 is not running, and 'url' is not pointing to any bean):

public class ConnectNow {

private void connect() {
    ClientDolphin dClient = new ClientDolphin();

    dClient.setClientModelStore(new ClientModelStore(dClient));
    String url = "http://localhost:8080/GrailsApplication1/";
    ClientConnector connector = new HttpClientConnector(dClient, url);
    connector.setCodec(new JsonCodec());
    dClient.setClientConnector(connector);
    dClient.send("Hi from client");
}

public static void main(String[] args) {
    ConnectNow cn = new ConnectNow();
    cn.connect();
    System.out.println("End");
}

}

Soo, how can I recognize if connection is established? I'm newbie in client/server dev, so maybe I'm missing something obvious.

Thanks for any advice, or doc reference!

rene
  • 41,474
  • 78
  • 114
  • 152
Václav
  • 365
  • 2
  • 15

1 Answers1

1

Now, I figured it out... Key is that I have to run the code as an Application, in this case javafx app. Then, if you try to transmit something (dClient send "Hi... - in this case), app tries to send a message, and you get ConnectException: Connection refused, if there is nothing running on url.

This seems to me as shortest version of open-dolphin server accessibity test:

import javafx.application.Application;
import javafx.stage.Stage;
import org.opendolphin.core.client.ClientDolphin;
import org.opendolphin.core.client.ClientModelStore;
import org.opendolphin.core.client.comm.ClientConnector;
import org.opendolphin.core.client.comm.HttpClientConnector;
import org.opendolphin.core.comm.JsonCodec;

/**
 *
 * @author Václav Hanton
 */
public class ConnectNow extends Application {

    private void connect() {
        ClientDolphin dClient = new ClientDolphin();

        ClientModelStore mStore = new ClientModelStore(dClient);
        dClient.setClientModelStore(mStore);
        String url = "http://localhost:8080/GrailsApplication1/";
        ClientConnector connector = new HttpClientConnector(dClient, url);
        connector.setCodec(new JsonCodec());

        dClient.setClientConnector(connector);
        dClient.send("Hi from client");
    }

    public static void main(String[] args) {
        ConnectNow cn = new ConnectNow();
        cn.connect();
        Application.launch();
    }

    @Override
    public void start(Stage stage) throws Exception {
        System.out.println("Started");
    }
}
Václav
  • 365
  • 2
  • 15
  • That is an interesting way to check the server availability ;-) Since you seem to run a Grails server, you could just as well check through the browser. BTW: please tag questions about open-dolphin with tag "opendolphin". Otherwise it may be noticed only much later. – Dierk Sep 17 '13 at 19:42
  • That was the real beginning;) As soon as I reach 1500 reputation points, I'll create open dolphin tag, but now, there is not any related tag on site. Now I try to use open-dolphin, or opendolphin at least in title. So I hope it can be found. Thanks – Václav Sep 17 '13 at 20:29
  • True, I have seen that restriction only afterwards :-) – Dierk Sep 18 '13 at 09:19
  • It appears the the tag was now created somehow! – Dierk Oct 12 '13 at 03:28
  • I thing it was rene who edited my dolphin questions by adding this tag. I thing it was about time to add it :) – Václav Oct 12 '13 at 14:34