2017-02-18 51 views
0

route.php頁面包含當我送現場通知的消息顯示錯誤:沒有連接可以

Route::get('/socket', '[email protected]'); 
Route::post('/sendmessage', '[email protected]'); 
Route::get('/writemessage', '[email protected]'); 

socketcontroller

<?php 
namespace App\Http\Controllers; 

//use Illuminate\Http\Request; 

use Request; 
use App\Http\Requests; 
use App\Http\Controllers\Controller; 
use LRedis; 

class socketController extends Controller 
{ 

    public function __construct() 
    { 
     $this->middleware('guest'); 
    } 

    public function index() 
    { 
     return view('AdminPanel.bladefiles.socket'); 
    } 

    public function writemessage() 
    { 
     return view('AdminPanel.bladefiles.writemessage'); 
    } 

    public function sendMessage() 
    { 
     $redis = LRedis::connection(); 
     $redis->publish('message', Request::input('message')); 
     return redirect('AdminPanel.bladefiles.writemessage'); 
    } 

} 

在我的socket.blade.php文件我寫了這段代碼,當我重定向到sendmessage()我得到了錯誤

No connection could be made because the target machine actively refused it. [tcp://127.0.0.1:6379]

<section class="content"> 
    <div class="row"> 
     <!-- left column --> 
     <div class="col-md-6"> 
      <!-- general form elements --> 
      <div class="box box-primary"> 
       <div class="box-header with-border"> 
        <h3 class="box-title">Live Notification</h3> 
        {{ csrf_field() }} 
       </div> 
       <!-- /.box-header --> 
       <!-- form start --> 
       <script src="//code.jquery.com/jquery-1.11.2.min.js"></script> 
       <script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script> 
       <script src="https://cdn.socket.io/socket.io-1.3.4.js"></script> 

       <div class="container"> 
        <div class="row"> 
         <div class="col-lg-8 col-lg-offset-2" > 
          <div id="messages" ></div> 
         </div> 
        </div> 
       </div> 
       <script> 
        var socket = io.connect('http://localhost:8000'); 
        socket.on('message', function (data) { 
         $("#messages").append("<p>" + data + "</p>"); 
        }); 
       </script> 
      </div> 
     </div> 
    </div> 
</section> 

回答

相關問題