GET http:// localhost:6001 / socket.io /?EIO = 3&transport = polling&t = MloS95c net :: ERR_CONNECTION_REFUSED

时间:2019-07-14 22:18:03

标签: laravel laravel-5 socket.io

我是非常新的laravel广播。我正在使用redis,socket.io和laravel echo。当我刷新页面时,这是在控制台上写的

  

获取http://localhost:6001/socket.io/?EIO=3&transport=polling&t=MloS95c   净:: ERR_CONNECTION_REFUSED

我的测试事件:

namespace App\Events;

use Illuminate\Broadcasting\Channel; use Illuminate\Queue\SerializesModels; use Illuminate\Broadcasting\PrivateChannel; use Illuminate\Broadcasting\PresenceChannel; use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Broadcasting\InteractsWithSockets; use Illuminate\Contracts\Broadcasting\ShouldBroadcast;

class TestEvent {
    use SerializesModels;
    public $message;

    /**
     * Create a new event instance.
     *
     * @return void
     */
    public function __construct($message)
    {
        $this->message = $message;

    }

    /**
     * Get the channels the event should broadcast on.
     *
     * @return \Illuminate\Broadcasting\Channel|array
     */
    public function broadcastOn()
    {
        return new Channel ('Message');
    }

}

我的头:

<script src="http://{{ Request::getHost() }}:6001/socket.io/socket.io.js"></script>

<meta name="csrf-token" content="{{ csrf_token() }}">

我的控制器:

public function dev(){
        event(new TestEvent("Hello"));
        return view('home');
    }

我的Js文件:

window.Echo.channel(`Message`)
    .listen('TestEvent', (data) => {
        console.log(data);
    });

1 个答案:

答案 0 :(得分:0)

由于laravel echo服务器未启动,您遇到此错误。在package.json文件中,在脚本下方添加以下行。

"scripts": {
    "start": "laravel-echo-server start",
     ```
},

现在,您需要进入控制台,并在项目根目录中运行npm start命令。它将启动lavavel回显服务器,错误将消失。