Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我尝试使用web套接字将一些对象从java服务器传输到有角度的web页面_Java_Angular_Web_Websocket - Fatal编程技术网

我尝试使用web套接字将一些对象从java服务器传输到有角度的web页面

我尝试使用web套接字将一些对象从java服务器传输到有角度的web页面,java,angular,web,websocket,Java,Angular,Web,Websocket,当我尝试将angular中的前端应用程序与java中的服务器连接起来,以便将一些对象从java发送到angular时,连接被拒绝,出现如下错误:GET net::ERR_connection_Deced。什么会导致这种问题 角度代码: import * as Stomp from 'stompjs'; import * as Socket from 'socket.io-client'; serverUrl = 'http://localhost:8082/ws' notify= "/

当我尝试将angular中的前端应用程序与java中的服务器连接起来,以便将一些对象从java发送到angular时,连接被拒绝,出现如下错误:GET net::ERR_connection_Deced。什么会导致这种问题

角度代码:

 import * as Stomp from 'stompjs';
 import * as Socket from 'socket.io-client';

 serverUrl = 'http://localhost:8082/ws'
 notify= "/notify/activity"

initializeWebSocketConnection(){
   let ws = new Socket(this.serverUrl);
   this.stompClient = Stomp.over(ws);
   let that = this;
   this.stompClient.connect({}, function(frame) {
     that.stompClient.subscribe(this.notify, (message) => {
       this.dangerousActivity=message;
       console.log(message);
     });
   });
 }
Java代码:

 @MessageMapping("/send/message")
    public void onReceivedMesage(String message){
        this.template.convertAndSend("/notify",  new SimpleDateFormat("HH:mm:ss").format(new Date())+"- "+message);
    }

 @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        registry.addEndpoint("/socket")
                .setAllowedOrigins("*")
                .withSockJS();
    }

   @Override
   public void configureMessageBroker(MessageBrokerRegistry registry) {
       registry.setApplicationDestinationPrefixes("/app")
               .enableSimpleBroker("/notify");
   }

我认为FE应用程序上的协议不正确!它应该是
ws://
而不是
http://
(serverUrl:
ws://localhost:8082/ws