java - 如何在 GWT 中使用 websocket

标签 java html gwt websocket

我想在 GWT 中启动 websockets,在使用异步回调之前,这是我之前如何工作的示例:

在包客户端中:

@RemoteServiceRelativePath("handler/categorieService")
 public interface CategorieServiceGwt extends RemoteService {

/**
 * Récupèrer la catégorie à travers l'identifiant passé en paramètre.
 * @param un identifiant de la catégorie.
 * @return la catégorie trouvée.
 */
CategorieModel getCategorieById(Long id) throws GwtRunTimeExceptionGwt;
}

异步接口(interface): 公共(public)接口(interface) CategoryServiceGwtAsync {

/**
 * Récupèrer la catégorie à travers l'identifiant passé en paramètre.
 * @param un identifiant de la catégorie.
 * @return la catégorie trouvée.
 */
void getCategorieById(Long id, AsyncCallback<CategorieModel> callback);

}

在包服务器中实现 CategorieServiceGwt 接口(interface):

public final class CategorieServiceGwtImpl implements CategorieServiceGwt {

private MapperDozerBean mapperDozerBean;

private CategorieService categorieService;

@Override
public CategorieModel getCategorieById(Long id) {
    return mapperDozerBean.map(categorieService.getCategorieById(id), CategorieModel.class);
}

所以我在互联网上看到了一些 websockets 的示例,但我不知道在这种情况下如何使用它?

最佳答案

我建议通过 native 绑定(bind)使用众所周知的 js 解决方案。 Websockets 和 comet 的问题最近才出现在您的项目中:2011 年,我在 GWT 库中遇到了一次糟糕的体验,其中连接已关闭,但我没有收到通知,无法重新连接等...

我花了两周时间来了解这个库,发现很多东西都需要重写。因此,如果您了解一个好的 js/jQuery 库,我建议您使用该库

关于java - 如何在 GWT 中使用 websocket,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23489526/

相关文章:

javascript - html 代码上的图表和操作

java - Tomcat 6.0 中正常 webapp 形式的 SHA-256 消息摘要(与领域无关)

java - Recyclerview 里面的 Recyclerview ,获取父 Adapter 里面子行的点击位置

java - 在Java中,有没有办法将一组可变大小的按钮居中(使用Swing)?

java - Hibernate 和数据库功能与包

html - CSS WordPress 菜单

java - 尝试使用 dom 解析 xml 页面时出现空指针异常

html - <i> 现在是 <em> 而 <b> 现在是 <strong>;但是<u>是什么?

gwt - 单独的 GWT UIBinder 文件

GWT : A widget that has an existing parent widget may not be added to the detach list