Java WebSocket消息代理的Android客户端
我需要在Android应用程序中管理单个WebSocket连接。为此,我实现了一个web应用程序,其中使用Spring设置了一个WebSocket消息代理 问题是我无法在Android应用程序中建立连接。我正在使用,但无法连接到订阅和发布主题(如带STOMP的SockJS)。 服务器(春季):Java WebSocket消息代理的Android客户端,java,android,spring,websocket,autobahn,Java,Android,Spring,Websocket,Autobahn,我需要在Android应用程序中管理单个WebSocket连接。为此,我实现了一个web应用程序,其中使用Spring设置了一个WebSocket消息代理 问题是我无法在Android应用程序中建立连接。我正在使用,但无法连接到订阅和发布主题(如带STOMP的SockJS)。 服务器(春季): 客户端(Autobahn Android): final String wsuri = "ws://" + HOSTNAME + ":" + PORT + "/myapp/ws"; mConnecti
客户端(Autobahn Android):
final String wsuri = "ws://" + HOSTNAME + ":" + PORT + "/myapp/ws";
mConnection.connect(wsuri, new Wamp.ConnectionHandler() {
@Override
public void onOpen() {
mConnection.subscribe("/myapp/ws/topic/poc", MyEntity.class, new Wamp.EventHandler() {
@Override
public void onEvent(String topicUri, Object event) { }
});
}
@Override
public void onClose(int code, String reason) {
// ERROR: Could not connect to /HOSTNAME...
}
});
我设法使用spring的简单处理程序而不是MessageBroker进行连接,但这限制了我每个连接只能“侦听”一个端点。。。谁能帮帮我吗?Autobahndroid实现WebSocket,而不是STOMP。与STOMP不同,WAMP同时提供发布和订阅以及远程过程调用
要使用WAMP,您需要一个WAMP路由器。您可以找到WAMP的客户端和路由器实现。谢谢@oberstet!我现在明白了。
final String wsuri = "ws://" + HOSTNAME + ":" + PORT + "/myapp/ws";
mConnection.connect(wsuri, new Wamp.ConnectionHandler() {
@Override
public void onOpen() {
mConnection.subscribe("/myapp/ws/topic/poc", MyEntity.class, new Wamp.EventHandler() {
@Override
public void onEvent(String topicUri, Object event) { }
});
}
@Override
public void onClose(int code, String reason) {
// ERROR: Could not connect to /HOSTNAME...
}
});