Connection timed out Laravel-echo-server

2k Views Asked by At

I know and I have seen this question

Getting ERR_CONNECTION_TIMED_OUT Laravel echo server

But I tried the solution in comment but it doesn't work.

I have my Laravel-echo-server.json

{
   "authHost": "https://mysite.it",
   "authEndpoint": "/broadcasting/auth",
   "clients": [],
   "database": "redis",
   "databaseConfig": {
   "redis": {
      "host":"0.0.0.0",
      "port":"6379",
      "password": "mypwd"
   },
   "sqlite": {
      "databasePath": "/database/laravel-echo-server.sqlite"
    }
  },
   "devMode": true,
   "host": null,
   "port": "6001",
   "protocol": "https",
   "socketio": {},
   "secureOptions": 67108864,
   "sslCertPath": "path_cert" ,
   "sslKeyPath": "path_key" ,
   "sslCertChainPath": "",
   "sslPassphrase": "",
   "subscribers": {
      "http": true,
      "redis": true
   },
   "apiOriginAllow": {
   "allowCors": true,
   "allowOrigin": "*",
   "allowMethods": "GET, PoST",
   "allowHeaders": "Origin, Content-Type, X-Auth-Token, X-Requested -With, Accept, Authorization, X-CSRF-TOKEN, X-Socket-IdOrigin, Content-Type, X-A uth-Token, X-Requested-With, Accept, Authorization, X-CSRF-TOKEN, X-Socket-IdOri gin, Content-Type, X-Auth-Token, X-Requested-With, Accept, Authorization, X-CSRF -TOKEN, X-Socket-Id"
   }
}

And I have in my bootstrapjs the connection with Frontend:

import Vue from 'vue'
import Echo from 'laravel-echo'
window.io = require('socket.io-client')
export var echo_instance = new Echo({
   broadcaster: 'socket.io',
   host: window.location.hostname + ':6001',
   auth: {
      headers: {
        'Authorization': "Bearer " + localStorage.getItem('token')
      }
   }
})
Vue.prototype.$echo = echo_instance
export default Vue

I have check if the port was closed but with netstat -an I can see:

tcp6 0 0 :::6001 :::* LISTEN

But when I try to launch my app i receive:

app.js:569 GET https://mysite.it:6001/socket.io/?EIO=3&transport=polling&t=NKoWZoK net::ERR_CONNECTION_TIMED_OUT

How can I use the laravel echo with https protocol?

2

There are 2 best solutions below

2
On

this might be because you have the wrong access token(dynamically added). why don't you try using a static access token first (copy the access token and paste it instead of localStorage.getItem('token')) for the user and see if it works.

Also try putting the following in laravel-echo-server.json file

"allowOrigin": "http://mysite.it:80"

And, see if APP_URL is different in .env file

0
On

in laravel-echo-server.json you have a section named socketio that you can put your socketio settings here.

{
  "sid": "FSDjX-WRwSA4zTZMALqx",
  "upgrades": ["websocket"],
  "pingInterval": 25000,
  "pingTimeout": 20000
}

according to socketio documentation (Handshake and pingTimeout) there is an option named pingTimeout and default timeout is set to 20000 ms. you can increase timeout time according to the needs of the project.