问题描述
我正在使用角度为8的套接字io更新记录异步。但这给了我以下错误。
开机自检 http://199.43.***.120:7171 / socket.io /?EIO = 3&transport = polling&t = NFPcfSj 405 (不允许使用方法)polyfills-es2015.19aa098ef024439a4e26.js:1
这是我用来构建服务器的代码。我已将app.js文件保存在src文件夹之外。
import { Injectable } from '@angular/core';
import * as io from 'socket.io-client';
import {Observable} from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class SocketServiceService {
socket: any;
readonly uri: string = 'ws://199.43.***.120:7171/';
constructor() {
this.socket = io(this.uri);
// this.socket = io(this.uri,{ transport : ['websocket'] });
}
listen(eventName: string) {
return new Observable((subscriber) => {
this.socket.on(eventName,(data) => {
subscriber.next(data);
});
});
}
emit(eventName: string,data: any) {
this.socket.emit(eventName,data);
}
}
这是我的app.js代码。
let app = require("express")();
let http = require("http").Server(app);
let io = require("socket.io")(http);
io.on("connection",socket => {
console.log("user connected");
socket.on('load appointment',function(id){
io.emit('get user appointment',id);
});
socket.on('add appointment',function(id){
io.emit('get user notification',id);
});
});
http.listen(5000,() => {
console.log("started on port 5000");
});
这是我的代码调用事件监听器。
eventListenerForAppointments() {
this.sockerService.listen('get user notification').subscribe((Id) => {
this.memberId = +Id;
this.getNotificationList();
});
}
注意:我已将app.js保留在src文件夹之外。我已经部署了我的角度应用程序远程IIS服务器。与ng:一起使用localhost:4000可以正常工作。但是部署后,这会在控制台上给我错误。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)