I have a Vert.X SockJS server running using the following code:
我有一个绿色的。使用以下代码运行的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);
Now I need to send messages from the server to an Android (and vice versa) application and I have no idea how to set that up on the client. The documentation talks about handling that in JavaScript but on the browser.
现在我需要从服务器向Android应用程序发送消息(反之亦然),我不知道如何在客户机上设置消息。文档讨论的是如何在JavaScript中处理,而不是在浏览器中。
UPDATE: I believe the following code is a bit in the right direction. I still need to add the host ip address (not sure how).
更新:我相信下面的代码有一点是正确的。我仍然需要添加主机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;
}
};
}
Thanks in advanced!
由于先进的!
1 个解决方案
#1
0
I think you can try a different way, if you want your android app to talk to a vertx server: using websocket, it is easier than using sockjs to setup a connection between them. Because I met and solved a similar requirement not long ago.
我认为你可以尝试一种不同的方式,如果你想让你的android应用程序与vertx服务器对话:使用websocket,比使用sockjs设置它们之间的连接更容易。因为不久前我遇到并解决了类似的要求。
Because websocket connection is a two-way channel, which means a vertx app could send text to your android app and vice versa. At the same time, there is Java-WebSocket(http://java-websocket.org/) which you can use for your android app. It is very easy to use.
因为websocket连接是一个双向通道,这意味着vertx应用可以向你的android应用发送文本,反之亦然。同时,还有Java-WebSocket(http://java-websocket.org/),你可以在你的android应用中使用它。
Also, to set up a websocket handler in vertx is not hard, there are many examples in document.
此外,在vertx中设置websocket处理器并不难,文档中有很多例子。
Good luck, :)
祝你好运,:)
#1
0
I think you can try a different way, if you want your android app to talk to a vertx server: using websocket, it is easier than using sockjs to setup a connection between them. Because I met and solved a similar requirement not long ago.
我认为你可以尝试一种不同的方式,如果你想让你的android应用程序与vertx服务器对话:使用websocket,比使用sockjs设置它们之间的连接更容易。因为不久前我遇到并解决了类似的要求。
Because websocket connection is a two-way channel, which means a vertx app could send text to your android app and vice versa. At the same time, there is Java-WebSocket(http://java-websocket.org/) which you can use for your android app. It is very easy to use.
因为websocket连接是一个双向通道,这意味着vertx应用可以向你的android应用发送文本,反之亦然。同时,还有Java-WebSocket(http://java-websocket.org/),你可以在你的android应用中使用它。
Also, to set up a websocket handler in vertx is not hard, there are many examples in document.
此外,在vertx中设置websocket处理器并不难,文档中有很多例子。
Good luck, :)
祝你好运,:)