websocket连不了,报错

f71976fa-8ad4-4249-b0ec-757a4135c207-78BB5273DE171F61FF896530AB87F5FF.jpg

importPackage(Packages["okhttp3"]); //导入包
var client = new OkHttpClient.Builder().retryOnConnectionFailure(true).build();
var request = new Request.Builder().url("ws://192.168.1.104:9317").build(); //vscode  插件的ip地址,
client.dispatcher().cancelAll();//清理一次
myListener = {
    onOpen: function (webSocket, response) {
        print("onOpen");
        //打开链接后,想服务器端发送一条消息
        var json = {};
        json.type = "hello";
        json.data = { device_name: "模拟设备", client_version: 123, app_version: 123, app_version_code: "233" };
        var hello = JSON.stringify(json);
        webSocket.send(hello);
    },
    onMessage: function (webSocket, msg) { //msg可能是字符串,也可能是byte数组,取决于服务器送的内容
        print("msg");
        print(msg);
    },
    onClosing: function (webSocket, code, response) {
        print("正在关闭");
    },
    onClosed: function (webSocket, code, response) {
        print("已关闭");
    },
    onFailure: function (webSocket, t, response) {
        print("错误");
        print(t);
    }
}
var webSocket = client.newWebSocket(request, new WebSocketListener(myListener)); //创建链接

setInterval(() => { // 防止主线程退出

}, 1000);

我也是是不是webSocket有問題,我數據都傳送不出去。然後跳出報錯是java.io.EOFException

@frsh1987 我能正常使用了,但不知道是什么原因,有可能是缓存的问题?这个bug还挺多的

我报错跟你们还不一样呢,add677d1-0d60-498d-90da-18ec5f38c8d9-image.png