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

已存档
Atom · 10 个月前

回答

十二
289
· 9 个月前

支持的哦

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
0
pikename
48
· 9 个月前

不支持的

0
0