我想在 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/