【发布时间】:2019-04-17 11:11:59
【问题描述】:
我一直收到net::ERR_CONNECTION_REFUSED,即使服务器没有运行。
当通过我的浏览器运行应用程序时,它可以正常工作,但是,然后通过设备并以本机方式运行,我得到了上述错误。
我觉得我已经尝试了一切来解决这个问题。我已经阅读了这么多相同问题的堆栈溢出问题。他们都没有帮助。
app.module:
import { SocketIoModule, SocketIoConfig } from 'ngx-socket-io';
const config: SocketIoConfig = { url: 'http:localhost:8080', options: {}};
注意:上面我也试过了:
'127.0.0.1:8080'
'127.0.0.1:8080/'
socketio 服务器:
const app = require('express')();
const PORT = process.env.CHAT_PORT || 3000;
const ENV = process.env.NODE_ENV || 'development';
const server = require('http').createServer(app , {origins: 'http://127.0.0.1:8100'});
const io = module.exports.io = require('socket.io')(server);
const SocketManager = require('./lib/SocketManager');
注意:我在origins: 中尝试了所有与上述相同的变体,除了更改端口,因为我的 Ionic 4 应用程序在端口 8100 上运行。我还尝试不包括 origins:
我的套接字服务:
import { Socket } from 'ngx-socket-io';
import { Observable } from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class ChatService {
constructor(private socket: Socket) {}
public sendMessage(msg: any){
this.socket.emit('new-message', msg);
}
public getMessages = () => {
return Observable.create(observer => {
this.socket.on('new-message', messageObj => {
observer.next(messageObj);
})
})
}
}
我期望它做的是连接,并让我的服务器注册已建立连接。
感谢您的帮助
更新:我已经这样配置了我的 config.xml:
<content original-src="index.html" src="http://192.168.1.38:8100" />
<access origin="*" />
<allow-navigation href="*" />
没有这样的运气。不过还是被屏蔽了
【问题讨论】:
标签: angular express socket.io ionic-native