idea 使用 websockt 连接错误


问题如下:
eclipse 启动项目完全没有问题,登录也没有问题,功能都正常,但是使用idea启动之后,登录websocket 连接错误 。如下图:
idea 使用 websockt 连接错误
页面代码如下:

//websocket开始
var websocket = null;

//判断当前浏览器是否支持WebSocket
if('WebSocket' in window){
    websocket = new WebSocket("ws://${webSocketURL}/message");
}else{
    alert('Not support websocket!');
}

//连接成功建立的回调方法
websocket.onopen = function(event){
    console.log('websocket连接成功![ws://${webSocketURL}/message]');
    websocket.send('userId:${operator.id}');
};

//连接关闭的回调方法
websocket.onclose = function(){
    layer.alert('服务器连接中断或用户在其它地方登录', {icon: 2,closeBtn: 0}, function(index){
        //转到登陆页面
        location.href='login.do';
        //关闭当前alert弹窗
        layer.close(index);
    });
};

//接收到消息的回调方法
websocket.onmessage = function(event){
    //var obj = JSON.parse(event.data);
    // layer.msg('['+event.data+']');
    // openNotice('default', event.data);
    openNotice('default', event.data, 5000);
    //重新查询未读消息数
    getUnreadMessageNum();
}
 
//连接发生错误的回调方法
websocket.onerror = function(){
    // layer.msg('连接websocket时发生错误!',1000);
    openNotice('danger', '连接websocket时发生错误!');
};
 
//监听窗口关闭事件,当窗口关闭时,主动去关闭websocket连接,防止连接还没断开就关闭窗口,server端会抛异常。
window.onbeforeunload = function(){
    websocket.close();
};

感觉应该不可能是开发工具的问题,但是目前还没有发现其他问题,重装系统idea还是连接错误,不知道是哪里的问题?求大神解难!!

相关文章:

  • 2022-12-23
  • 2021-06-03
  • 2022-12-23
  • 2021-08-24
  • 2022-01-23
  • 2022-01-18
  • 2021-09-21
猜你喜欢
  • 2022-12-23
  • 2021-12-06
  • 2021-03-26
  • 2021-11-01
  • 2022-12-23
  • 2021-11-17
相关资源
相似解决方案