简体   繁体   English

WebSocket 连接失败:连接建立错误

[英]WebSocket Connection failed: error in connection establishment

The following code is client and server side code to use webRTC connection.以下代码是使用 webRTC 连接的客户端和服务器端代码。 It's working perfectly in localhost.它在本地主机中完美运行。 when i deployed to linux shared hosting server., it's getting error.当我部署到 linux 共享托管服务器时,出现错误。

This is my server side code.这是我的服务器端代码。

var http = require('http');
var express = require('express');
var ExpressPeerServer = require('peer').ExpressPeerServer;

var app = express();

var server = http.createServer(app);

var options = {
    debug: true,
    key: 'peerjs',
    allow_discovery: true,
    ssl: {
        key: '',
        cert: ''
    },
    proxied: true
};
var expressPeerServer = ExpressPeerServer(server, options);

app.use('/api', expressPeerServer);
app.use('/', express.static('.'));

app.use('/list', function (req, res) {
    return res.json(Object.keys(expressPeerServer._clients.peerjs));
});

var port = process.env.PORT || 8080;
server.listen(port, function () {
    console.log('Basic-ss live at', port);
});

expressPeerServer.on('connection', function (id) {
    console.log('Peer connected with id:', id);
});

expressPeerServer.on('disconnect', function (id) {
    console.log('Peer %s disconnected', id);
});

the following is the client side code for connect peer.以下是connect peer的客户端代码。

initPeer(peerId) {
        this.peer = new Peer(peerId, {
            host: 'localhost',
            port: 8080,
            path: '/api',
            key: 'peerjs',
            debug: 3,
            config: {
                'iceServers': [
                    { url: 'stun:stun.l.google.com:19302' },
                ]
            }
        });
        setTimeout(() => {
            this.currentPeerId = this.peer.id;
            if (this.currentPeerId !== null) {
                isPeerConnected = true;
            } else {
                isPeerConnected = false;
            }
            console.log('Current Peer ID', this.currentPeerId);
        }, 4000);
    }

this code is working perfectly in localhost.这段代码在本地主机上运行良好。 this is the code i am uploading in server.这是我在服务器中上传的代码。

this.peer = new Peer(peerId, {
            host: '',  ===> my domain name here.
            port: 8080,
            path: '/api',
            key: 'mebstelemedclinic',
            debug: 3,
            config: {
                'iceServers': [
                    { url: 'stun:stun.l.google.com:19302' },
                    {
                        url: 'turn:192.158.29.39:3478?transport=udp',
                        credential: 'JZEOEt2V3Qb0y27GRntt2u2PAYA=',
                        username: '28224511:1379330808'
                    }
                ]
            }
        });

if use the same server code and the above client side code., it's getting connection error.如果使用相同的服务器代码和上述客户端代码,则会出现连接错误。

WebSocket connection to 'wss://mydomain.in:8080/api/peerjs?key=peerjs&id=LY42201PH-yKy04f-ygqZJhqrBmezG6&token=n42tatqqn9e' failed: Error in connection establishment: net::ERR_CONNECTION_TIMED_OUT

i was struck at this point from long time.很长一段时间以来,我在这一点上受到了打击。 Help me how can i overcome this error.帮助我如何克服这个错误。 thank you.谢谢你。

You should add the code below to your path nano site_name in /etc/nginx/sites-available :您应该将以下代码添加到/etc/nginx/sites-available路径 nano site_name :

location  {       
  proxy_pass Ip address;         proxy_http_version 1.1;         proxy_set_header Upgrade $http_upgrade;         proxy_set_header Connection "upgrade";         proxy_set_header Host $host;     } 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 chrome 扩展 WebSocket 连接到“ws://localhost:9090/”失败:连接建立错误:net::ERR_CONNECTION_REFUSED - chrome extension WebSocket connection to 'ws://localhost:9090/' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED WebSocket 连接到“wss://ip:8080/”失败:连接建立错误:net::ERR_CONNECTION_REFUSED - WebSocket connection to 'wss://ip:8080/' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED WebSocket 连接失败:连接建立时出错:.net::ERR_CONNECTION_REFUSED - WebSocket connection failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED Websocket连接被拒绝。 WebSocket与'ws://127.0.0.1:2000 /'的连接失败:连接建立错误:net :: ERR_CONNECTION_REFUSED - Websocket connection refused. WebSocket connection to 'ws://127.0.0.1:2000/' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED 与'ws://。/'的WebSocket连接失败:连接建立错误:net :: ERR_NAME_NOT_RESOLVED - WebSocket connection to 'ws://./' failed: Error in connection establishment: net::ERR_NAME_NOT_RESOLVED twilio.min.js:77 WebSocket 连接到'wss://chunderw-vpc-gll.twilio.com/signal'连接失败: - twilio.min.js:77 WebSocket connection to 'wss://chunderw-vpc-gll.twilio.com/signal' failed: Error in connection establishment: 失败:连接建立时出错:.net::ERR_CONNECTION_REFUSED - Failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED 连接建立错误:尝试建立并连接到Websocket服务器时,抛出net :: ERR_SSL_PROTOCOL_ERROR - Error in connection establishment: net::ERR_SSL_PROTOCOL_ERROR is thrown when trying establish and connect to a websocket server Kurento - WebSocket连接失败 - Kurento - WebSocket Connection failed wss上的WebSocket连接失败 - WebSocket connection on wss failed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM