簡體   English   中英

WebSocket 連接到“wss://ip:8080/”失敗:連接建立錯誤:net::ERR_CONNECTION_REFUSED

[英]WebSocket connection to 'wss://ip:8080/' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED

var FancyWebSocket = function(url)
    {
        var callbacks = {};
        var ws_url = url;
        var conn;

        this.bind = function(event_name, callback){
            callbacks[event_name] = callbacks[event_name] || [];
            callbacks[event_name].push(callback);
            return this;// chainable
        };

        this.send = function(event_name, event_data){
            //this.conn.send(event_data);
            this.conn.onopen = () => this.conn.send(event_data);
            return this;
        };

        this.connect = function() {
            if ( typeof(MozWebSocket) == 'function' )
                this.conn = new MozWebSocket(url);
            else
                this.conn = new WebSocket(url);

            // dispatch to the right handlers
            this.conn.onmessage = function(evt){
                dispatch('message', evt.data);
            };

            this.conn.onclose = function(){dispatch('close',null)}
            this.conn.onopen = function(){dispatch('open',null)}
        };

        this.disconnect = function() {
            this.conn.close();
        };

        var dispatch = function(event_name, message){
            if(message == null || message == "")
            {
            } 
            else
            {
                video(message);
            }
        }
    };

    var Server;
    function send( text )
    {
        Server.send( 'message', text );
    }
    $(document).ready(function(){
        Server = new FancyWebSocket('wss://103.211.219.27:8080');
        Server.bind('open', function()
        {
        });
        Server.bind('close', function(data)
        {
        });
        Server.bind('message', function(payload)
        {
        });
        Server.connect();
    });

這是我之前被問到但沒有得到任何答案的問題。 在這段代碼中,我正在通過 IP 和端口構建視頻直播,但出現錯誤,即

WebSocket 連接到“wss://ip:8080/”失敗:連接建立錯誤:net::ERR_CONNECTION_REFUSED

我不知道為什么會這樣。 我已經擁有我的域的 SSL 這就是為什么我使用wss但我仍然有同樣的問題。 我的控制台中總是出現此錯誤this.conn = new WebSocket(url); . 那么,如何通過 websocket 建立成功連接? 請幫我。

謝謝你

在 jquery 替換

服務器 = 新的 FancyWebSocket('ws://103.211.219.27:8080')

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM