回答
支持的哦
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