2017-04-06 1 views
0

チャットアプリケーションを構築するためにMAMPサーバーにsocket.ioを正常に実装しました。プロダクションサーバー(デジタル海洋、ラーベルフォージ)にプッシュすると、エラー取得: enter image description hereLetsEncrypt、Redis、Laravel Forge&Digital OceanとのSocket.io

私はthis articleに基づいフォージのデーモンを設定し、this

マイsocket.jsファイルに基づいて手順をインストールし、その後はこれです:

var server = require('http').Server(); 

var io = require('socket.io')(server); 

var Redis = require('ioredis'); 
var redis = new Redis(); 

redis.subscribe('test-channel'); 

redis.on('message', function(channel, message, username) { 
    console.log(channel + ":" + message); 
    message = JSON.parse(message); 

    io.emit(channel + ":" + message.event, message.data); // test-channel:nameOfEvent (UserSignedUp) 
}); 

server.listen(3000); 

私のブレードのファイル:

<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/1.7.3/socket.io.min.js"></script> 
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/0.12.15/vue.min.js"></script> 
<script> 
//var socket = io('{{ Request::ip() }}:3000'); 
var socket = io('server.ip.address:3000'); //initalize socket 

socket.on('test-channel:App\\Events\\NewChatMessage', function(message){ 
    //console.log(message.messages); 
    if(message.messages.company_id == {{ Auth::user()->company_id }}){ 
     if(message.messages.user_id != {{ Auth::user()->id }}) 
     { 
      var html = '<div class="direct-chat-msg"><div class="direct-chat-info clearfix"><span class="direct-chat-name pull-left">' + message.username + '</span><span class="direct-chat-timestamp pull-right">time</span></div><!-- /.direct-chat-info --><div class="other avatar direct-chat-img">' + message.avatar + '</div><!-- /.direct-chat-img --><div class="direct-chat-text">' + message.messages.body + '</div><!-- /.direct-chat-text --></div><!-- /.direct-chat-msg -->'; 
     } else { 
      var html = '<div class="direct-chat-msg right"><div class="direct-chat-info clearfix"><span class="direct-chat-name pull-right">' + message.username + '</span><span class="direct-chat-timestamp pull-left">time</span></div><!-- /.direct-chat-info --><div class="avatar direct-chat-img">' + message.avatar + '</div><!-- /.direct-chat-img --><div class="direct-chat-text">' + message.messages.body + '</div><!-- /.direct-chat-text --></div><!-- /.direct-chat-msg --></div><!--/.direct-chat-messages-->'; 
     } 
     $('.direct-chat-messages').append(html); 
     $(".direct-chat-messages").animate({ scrollTop: $('.direct-chat-messages').prop("scrollHeight")}, 1000); 
    } 
    /*for (var i = 0; i < message.threads.length; i++) { 
     var counter = message.threads[i]; 
     console.log(counter.subject); 
    }*/ 
    //this.messages.push(message); 
}); //listen for chat.message event and update messages 

私は本番環境にチャットメッセージを送信すると、私は理由socket.jsにconsole.logの端子にそれを参照してください、そのだけのフロントエンドを打っていません。もし私が賭けていたら(おそらくそのベットを失う)、http://example.comの代わりにhttps://example.comを使っているからです。それが問題のように思えたら、socket.jsがhttpではなくhttpsを使用していることをどうすれば確認できますか?

Laravelログは、redisとsocket.ioの両方が正常に動作していることを示しています。

UPDATE はここで、それは誰かが起こっているかを見ることができます場合には、私の限られた知識に基づいて、クライアント側の問題のように思えるクロームで印刷ログです。

socket.io.min.js:1 socket.io-client:url parse https://example.com:3000 +0ms 
socket.io.min.js:1 socket.io-client new io instance for https://example.com:3000 +3ms 
socket.io.min.js:1 socket.io-client:manager readyState closed +2ms 
socket.io.min.js:1 socket.io-client:manager opening https://example.com:3000 +0ms 
socket.io.min.js:1 engine.io-client:socket creating transport "polling" +1ms 
socket.io.min.js:1 engine.io-client:polling polling +1ms 
socket.io.min.js:1 engine.io-client:polling-xhr xhr poll +0ms 
socket.io.min.js:1 engine.io-client:polling-xhr xhr open GET: https://example.com:3000/socket.io/?EIO=3&transport=polling&t=LjBd72n +2ms 
socket.io.min.js:1 engine.io-client:polling-xhr xhr data null +0ms 
socket.io.min.js:1 engine.io-client:socket setting transport polling +2ms 
socket.io.min.js:1 socket.io-client:manager connect attempt will timeout after 20000 +0ms 
socket.io.min.js:1 socket.io-client:manager readyState opening +2ms 
messages:217 GET https://example.com/files/designloud-inc/users/ 403() 
messages:1 GET https://example.com:3000/socket.io/?EIO=3&transport=polling&t=LjBd72n net::ERR_CONNECTION_TIMED_OUT 
socket.io.min.js:1 engine.io-client:socket socket error {"type":"TransportError","description":0} +8s 
socket.io.min.js:1 socket.io-client:manager connect_error +0ms 
socket.io.min.js:1 socket.io-client:manager cleanup +1ms 
socket.io.min.js:1 socket.io-client:manager will wait 978ms before reconnect attempt +1ms 
socket.io.min.js:1 engine.io-client:socket socket close with reason: "transport error" +0ms 
socket.io.min.js:1 engine.io-client:polling transport not open - deferring close +1ms 
socket.io.min.js:1 socket.io-client:manager attempting reconnect +981ms 
socket.io.min.js:1 socket.io-client:manager readyState closed +0ms 
socket.io.min.js:1 socket.io-client:manager opening https://example.com:3000 +0ms 
socket.io.min.js:1 engine.io-client:socket creating transport "polling" +1ms 
socket.io.min.js:1 engine.io-client:polling polling +1ms 
socket.io.min.js:1 engine.io-client:polling-xhr xhr poll +0ms 
socket.io.min.js:1 engine.io-client:polling-xhr xhr open GET: https://example.com:3000/socket.io/?EIO=3&transport=polling&t=LjBd9Hj +1ms 
socket.io.min.js:1 engine.io-client:polling-xhr xhr data null +0ms 
socket.io.min.js:1 engine.io-client:socket setting transport polling +1ms 
socket.io.min.js:1 socket.io-client:manager connect attempt will timeout after 20000 +1ms 
:3000/socket.io/?EIO=3&transport=polling&t=LjBd9Hj:1 GET https://example.com:3000/socket.io/?EIO=3&transport=polling&t=LjBd9Hj net::ERR_CONNECTION_TIMED_OUT 
socket.io.min.js:1 engine.io-client:socket socket error {"type":"TransportError","description":0} +8s 
socket.io.min.js:1 socket.io-client:manager connect_error +1ms 
socket.io.min.js:1 socket.io-client:manager cleanup +0ms 
socket.io.min.js:1 socket.io-client:manager reconnect attempt error +1ms 
socket.io.min.js:1 socket.io-client:manager will wait 1132ms before reconnect attempt +0ms 
socket.io.min.js:1 engine.io-client:socket socket close with reason: "transport error" +1ms 
socket.io.min.js:1 engine.io-client:polling transport not open - deferring close +0ms 
socket.io.min.js:1 socket.io-client:manager attempting reconnect +1s 
socket.io.min.js:1 socket.io-client:manager readyState closed +0ms 
socket.io.min.js:1 socket.io-client:manager opening https://example.com:3000 +1ms 
socket.io.min.js:1 engine.io-client:socket creating transport "polling" +0ms 
socket.io.min.js:1 engine.io-client:polling polling +1ms 
socket.io.min.js:1 engine.io-client:polling-xhr xhr poll +0ms 
socket.io.min.js:1 engine.io-client:polling-xhr xhr open GET: https://example.com:3000/socket.io/?EIO=3&transport=polling&t=LjBdBXX +1ms 
socket.io.min.js:1 engine.io-client:polling-xhr xhr data null +0ms 
socket.io.min.js:1 engine.io-client:socket setting transport polling +1ms 
socket.io.min.js:1 socket.io-client:manager connect attempt will timeout after 20000 +1ms 
:3000/socket.io/?EIO=3&transport=polling&t=LjBdBXX:1 GET https://example.com:3000/socket.io/?EIO=3&transport=polling&t=LjBdBXX net::ERR_CONNECTION_TIMED_OUT 
socket.io.min.js:1 engine.io-client:socket socket error {"type":"TransportError","description":0} +8s 
socket.io.min.js:1 socket.io-client:manager connect_error +1ms 
socket.io.min.js:1 socket.io-client:manager cleanup +0ms 
socket.io.min.js:1 socket.io-client:manager reconnect attempt error +1ms 
socket.io.min.js:1 socket.io-client:manager will wait 5000ms before reconnect attempt +0ms 
socket.io.min.js:1 engine.io-client:socket socket close with reason: "transport error" +1ms 
socket.io.min.js:1 engine.io-client:polling transport not open - deferring close +0ms 
socket.io.min.js:1 socket.io-client:manager attempting reconnect +5s 
socket.io.min.js:1 socket.io-client:manager readyState closed +1ms 
socket.io.min.js:1 socket.io-client:manager opening https://example.com:3000 +0ms 
socket.io.min.js:1 engine.io-client:socket creating transport "polling" +1ms 
socket.io.min.js:1 engine.io-client:polling polling +0ms 
socket.io.min.js:1 engine.io-client:polling-xhr xhr poll +1ms 
socket.io.min.js:1 engine.io-client:polling-xhr xhr open GET: https://example.com:3000/socket.io/?EIO=3&transport=polling&t=LjBdEkE +0ms 
socket.io.min.js:1 engine.io-client:polling-xhr xhr data null +1ms 
socket.io.min.js:1 engine.io-client:socket setting transport polling +1ms 
socket.io.min.js:1 socket.io-client:manager connect attempt will timeout after 20000 +0ms 
:3000/socket.io/?EIO=3&transport=polling&t=LjBdEkE:1 GET https://example.com:3000/socket.io/?EIO=3&transport=polling&t=LjBdEkE net::ERR_CONNECTION_TIMED_OUT 
socket.io.min.js:1 engine.io-client:socket socket error {"type":"TransportError","description":0} +5s 
socket.io.min.js:1 socket.io-client:manager connect_error +1ms 
socket.io.min.js:1 socket.io-client:manager cleanup +0ms 
socket.io.min.js:1 socket.io-client:manager reconnect attempt error +1ms 
socket.io.min.js:1 socket.io-client:manager will wait 5000ms before reconnect attempt +0ms 
socket.io.min.js:1 engine.io-client:socket socket close with reason: "transport error" +1ms 
socket.io.min.js:1 engine.io-client:polling transport not open - deferring close +0ms 
socket.io.min.js:1 socket.io-client:manager attempting reconnect +5s 
socket.io.min.js:1 socket.io-client:manager readyState closed +1ms 
socket.io.min.js:1 socket.io-client:manager opening https://example.com:3000 +0ms 
socket.io.min.js:1 engine.io-client:socket creating transport "polling" +0ms 
socket.io.min.js:1 engine.io-client:polling polling +1ms 
socket.io.min.js:1 engine.io-client:polling-xhr xhr poll +0ms 
socket.io.min.js:1 engine.io-client:polling-xhr xhr open GET: https://example.com:3000/socket.io/?EIO=3&transport=polling&t=LjBdH5N +1ms 
socket.io.min.js:1 engine.io-client:polling-xhr xhr data null +0ms 
socket.io.min.js:1 engine.io-client:socket setting transport polling +1ms 
socket.io.min.js:1 socket.io-client:manager connect attempt will timeout after 20000 +1ms 
:3000/socket.io/?EIO=3&transport=polling&t=LjBdH5N:1 GET https://example.com:3000/socket.io/?EIO=3&transport=polling&t=LjBdH5N net::ERR_CONNECTION_TIMED_OUT 
socket.io.min.js:1 engine.io-client:socket socket error {"type":"TransportError","description":0} +4s 
socket.io.min.js:1 socket.io-client:manager connect_error +1ms 
socket.io.min.js:1 socket.io-client:manager cleanup +0ms 
socket.io.min.js:1 socket.io-client:manager reconnect attempt error +1ms 
socket.io.min.js:1 socket.io-client:manager will wait 5000ms before reconnect attempt +0ms 
socket.io.min.js:1 engine.io-client:socket socket close with reason: "transport error" +1ms 
socket.io.min.js:1 engine.io-client:polling transport not open - deferring close +0ms 
socket.io.min.js:1 socket.io-client:manager attempting reconnect +5s 
socket.io.min.js:1 socket.io-client:manager readyState closed +1ms 
socket.io.min.js:1 socket.io-client:manager opening https://example.com:3000 +0ms 
socket.io.min.js:1 engine.io-client:socket creating transport "polling" +1ms 
socket.io.min.js:1 engine.io-client:polling polling +0ms 
socket.io.min.js:1 engine.io-client:polling-xhr xhr poll +1ms 
socket.io.min.js:1 engine.io-client:polling-xhr xhr open GET: https://example.com:3000/socket.io/?EIO=3&transport=polling&t=LjBdJAO +0ms 
socket.io.min.js:1 engine.io-client:polling-xhr xhr data null +1ms 
socket.io.min.js:1 engine.io-client:socket setting transport polling +1ms 
socket.io.min.js:1 socket.io-client:manager connect attempt will timeout after 20000 +0ms 
+0

は、これらの質問の両方が同じ問題Imは持っていないが、どちらも、私の問題を理解することが容易である場合には答えを持っている:http://stackoverflow.com/questions/37026314/socket-io-timeout-on-laravel-forge?rq = 1 http://stackoverflow.com/questions/35635174/laravel-forge-node-js-websocket-timeout?rq=1 – Derek

答えて

0

は、私たちは、有効にする証明書をロードする必要がsocket.io以上のhttps

パブリックフォルダに「SSL」という名前のフォルダを作成し、

SSLCertificateFile: /your_ssl_dir/yourcertificate.crt 
SSLCertificateKeyFile: /your_ssl_dir/website_ssl.key 
SSLCertificateChainFile: /your_ssl_dir/yourchain.crt 
to ssl 

これらのファイルがある次のファイルをコピーします証明書に署名するためにsocket.ioが必要とします。

は、その後、次の変更を行います

var app = require('express')(); 
var fs = require('fs'); 
var options = { 
    key: fs.readFileSync('ssl/website_ssl.key'), 
    cert: fs.readFileSync('ssl/yourcertificate.crt'), 
    ca:  fs.readFileSync('ssl/yourchain.crt') 
}; 
var server = require('https').Server(options,app); 
var Redis = require('ioredis'); 
var io = require('socket.io')(server); 
+0

エラーが発生しましたアクセス許可が拒否されているため、証明書のファイルをダウンロード、編集、または開くことはできません。 – Derek

+0

rootレベルのユーザーから試してください – sumit

+0

端末でこれを行うのですか?これは私のための新しいすべての領域です、あなたは例を挙げることができますか? – Derek

関連する問題