Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/30.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
Angular 7-Websocket-SockJS和StompJS-Java后端。连接有时会随机关闭_Angular_Websocket_Spring Websocket_Stompjs - Fatal编程技术网

Angular 7-Websocket-SockJS和StompJS-Java后端。连接有时会随机关闭

Angular 7-Websocket-SockJS和StompJS-Java后端。连接有时会随机关闭,angular,websocket,spring-websocket,stompjs,Angular,Websocket,Spring Websocket,Stompjs,我曾经创建过连接,虽然它通常可以正常工作,但有时甚至在连接之前就关闭了连接。我注意到这通常发生在网络呼叫失败时。我不确定此调用是否由StomJS库发出,以及如何确保连接在失败时重新连接?任何建议都会有帮助 publicsid:string; 公共stompClient:任何; public webSocketData$:BehaviorSubject=新的BehaviorSubject(null); 构造函数(私有存储:存储,私有环境服务:环境配置服务){ this.store.select(

我曾经创建过连接,虽然它通常可以正常工作,但有时甚至在连接之前就关闭了连接。我注意到这通常发生在网络呼叫失败时。我不确定此调用是否由StomJS库发出,以及如何确保连接在失败时重新连接?任何建议都会有帮助

publicsid:string;
公共stompClient:任何;
public webSocketData$:BehaviorSubject=新的BehaviorSubject(null);
构造函数(私有存储:存储,私有环境服务:环境配置服务){
this.store.select(frommanstore.getLoggedInUserSid).subscribe((resp)=>{
this.sid=resp;
this.initializeWebSocketConnection();
});
}
初始化WebSocketConnection(){
const header={sid:this.sid};
this.stompClient=Stomp.over(()=>newsockjs(this.envService.envConfig.EVENT_URL));
this.stompClient.connect(头,(帧)=>{
this.stompClient.subscribe('/user/'+this.sid,(resp)=>{
this.webSocketData$.next(JSON.parse(resp.body));
});
},err=>{
console.log('连接错误',err);
this.stompClient.reconnect_delay=5000;
});
}
getWebSocketData():可观察{
返回此.webSocketData$.asObservable();
}