简体   繁体   English

如何从Android连接到Spring Websocket

[英]how to connect to spring websocket from android

i am using grails 3.1.1 我正在使用Grails 3.1.1

i already try to find some documentation and question like this . 我已经尽量找一些文档和问题,像这样

this is my code in ChatController 这是我在ChatController代码

class ChatController {

    SimpMessagingTemplate brokerMessagingTemplate
    def corporateUserService
    def index={

    }

    @MessageMapping("/chat")
    @SendTo("/queue/chat")
    protected String hello(DestinationUser map) {
        brokerMessagingTemplate.convertAndSend "/queue/chat", map
    }
}

and i already deploy this application, for example : 并且我已经部署了此应用程序,例如:

https://somedomain.com https://somedomain.com

how can i connect from android to my webapplication's websocket? 如何从android连接到Web应用程序的websocket?

i tried 我试过了

wss://somedomain.com/chat WSS://somedomain.com/chat
wss://somedomain.com/queue/chat WSS://somedomain.com/queue/chat

but it still cannot connect. 但仍然无法连接。

i am trying follow this tutorial github 我正在尝试按照本教程github

like this.. 像这样..

AsyncHttpClient.getDefaultInstance().websocket("ws://satubangau.com/app/hello", null, new AsyncHttpClient.WebSocketConnectCallback() {
        @Override
        public void onCompleted(Exception ex, WebSocket webSocket) {
            Log.d(TAG, "onCompleted: ");
            if (ex != null) {
                ex.printStackTrace();
                return;
            }
            webSocket.send("a string");
            webSocket.send(new byte[10]);
            webSocket.setStringCallback(new WebSocket.StringCallback() {
                public void onStringAvailable(String s) {
                    Log.d(TAG, "onStringAvailable: I got a string: " + s);
                }
            });
            webSocket.setDataCallback(new DataCallback() {
                public void onDataAvailable(DataEmitter emitter, ByteBufferList byteBufferList) {
                    Log.d(TAG, "onDataAvailable: I got some bytes!");
                    // note that this data has been read
                    byteBufferList.recycle();
                }
            });
        }
    });

but i get the log like this.. 但是我得到这样的日志..

在此处输入图片说明

您是否尝试过在Android上使用WebSocket客户端库,例如https://github.com/koush/AndroidAsync

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM