1
我使用下面的代碼Vert.X SockJS服務器上運行:與Vert.X SockJS服務器的Android 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;
}
};
}
謝謝先進!