我有一个使用以下代码运行的 Vert.X SockJS 服务器:
HttpServer httpServer = vertx.createHttpServer();
SockJSServer sockJSServer = vertx.createSockJSServer(httpServer);
JsonObject config = new JsonObject().putString("prefix", "/echo");
sockJSServer.installApp(config, new Handler<SockJSSocket>() {
public void handle(SockJSSocket sock) {
Pump.createPump(sock, sock).start();
}
});
httpServer.listen(8080);
现在我需要将消息从服务器发送到 Android(反之亦然)应用程序,但我不知道如何在客户端上进行设置。该文档讨论了在 JavaScript 中但在浏览器上的处理。
更新:我相信下面的代码有点朝着正确的方向。我仍然需要添加主机 IP 地址(不确定如何)。
public void start() {
SockJSSocket client = new SockJSSocketBase(vertx){
@Override
public boolean writeQueueFull(){
// TODO Auto-generated method stub
return false;
}
@Override
public SockJSSocket setWriteQueueMaxSize(int arg0){
// TODO Auto-generated method stub
return null;
}
@Override
public SockJSSocket drainHandler(Handler<Void> arg0){
// TODO Auto-generated method stub
return null;
}
@Override
public SockJSSocket write(Buffer arg0){
// TODO Auto-generated method stub
return null;
}
@Override
public SockJSSocket exceptionHandler(Handler<Throwable> arg0){
// TODO Auto-generated method stub
return null;
}
@Override
public SockJSSocket resume(){
// TODO Auto-generated method stub
return null;
}
@Override
public SockJSSocket pause(){
// TODO Auto-generated method stub
return null;
}
@Override
public SockJSSocket dataHandler(Handler<Buffer> arg0){
// TODO Auto-generated method stub
return null;
}
@Override
public SockJSSocket endHandler(Handler<Void> arg0){
// TODO Auto-generated method stub
return null;
}
};
}
先谢谢了!