gpt4 book ai didi

java - 我缺少类似 : 'isConnected' on ClientDolphin class (open-dolphin) 的内容

转载 作者:行者123 更新时间:2023-11-30 11:30:13 25 4
gpt4 key购买 nike

如果我按照 java 类运行,没有异常或错误消息发生,但我确定无法建立连接(GrailsApplication1 未运行,并且“url”未指向任何 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,我如何识别连接是否建立?我是客户端/服务器开发的新手,所以我可能遗漏了一些明显的东西。

感谢您的任何建议或文档引用!

最佳答案

现在,我想通了...关键是我必须将代码作为应用程序运行,在本例中为 javafx 应用程序。然后,如果您尝试传输某些内容(dClient 发送“嗨... - 在这种情况下),应用程序会尝试发送一条消息,并且您会收到 ConnectException: Connection refused,如果没有任何内容正在运行网址

在我看来,这是 open-dolphin 服务器可访问性测试的最短版本:

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");
}
}

关于java - 我缺少类似 : 'isConnected' on ClientDolphin class (open-dolphin) 的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17901710/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com