这个 支持 websocket 吗 没有在文档里面看到

已存档
Atom · 1 年前

回答

十二
289
· 1 年前

支持的哦

var mClient = new OkHttpClient();
//这里是服务端相对于手机端的ip
var request = new Request.Builder().get().url("ws://192.168.0.100:8180/").build();
var globalWebsocket = null;
function init() {
    mClient.newWebSocket(request, new JavaAdapter(WebSocketListener, {
        onOpen: function (webSocket, response) {
            globalWebsocket=webSocket;
            console.log("开启连接成功")
        },
        onMessage: function (webSocket, text) {
            console.log("c<===="+text);
        },
        onClosed: function (webSocket, code,reason) {
           console.log("onclose")
        },   
        onFailure: function (webSocket, throwable,response) {
            console.log("onFailure")
            console.log(webSocket, throwable,response)
        },
    }));
}
globalWebsocket.send("消息");
1
pikename
88
· 1 年前

不支持的

0