DEV Community

Prathamesh Patil
Prathamesh Patil

Posted on

1

Websocket - With Socket.io & Lravel echo

As we all know about web-sockets ,as some times it may go difficult to implement. Here I will Mention the Perfect Simplified steps to implement a Web-socket for Front-end I have chosen Veu.js

Here we are going to Use Redis - So First We have to Install Redis pon our system



sudo apt install redis-server


Enter fullscreen mode Exit fullscreen mode

Lets Start with Laravel

Step 1: Install Following Packages



 i)composer require predis/predis,
 ii)composer require illuminate/redis


Enter fullscreen mode Exit fullscreen mode

Step 2: Add Following Line in .env file



REDIS_HOST = localhost
REDIS_PASSWORD = null
REDIS_PORT = 6379
REDIS_DB = 0

BROADCAST_DRIVER=redis


Enter fullscreen mode Exit fullscreen mode

Step 3:Now Install laravel-echo-server globally with command



npm install -g laravel-echo-server


Enter fullscreen mode Exit fullscreen mode

Step 4: Now in your Projects Root Folder run following command



laravel-echo-server init


Enter fullscreen mode Exit fullscreen mode

After running above command it will ask you following questions - ans is appropriately as eg below is mine on local machine



? Do you want to run this server in development mode? Yes
? Which port would you like to serve from? 6001
? Which database would you like to use to store presence channel members? redis
? Enter the host of your Laravel authentication server. http://localhost
? Will you be serving on http or https? http
? Do you want to generate a client ID/Key for HTTP API? No
? Do you want to setup cross domain access to the API? No
? What do you want this config to be saved as? laravel-echo-server.json



Enter fullscreen mode Exit fullscreen mode

Step 5: - Now start the Laravel Echo Server By command



laravel-echo-server start 


Enter fullscreen mode Exit fullscreen mode

This will look like below :-

Alt Text

AWS GenAI LIVE image

How is generative AI increasing efficiency?

Join AWS GenAI LIVE! to find out how gen AI is reshaping productivity, streamlining processes, and driving innovation.

Learn more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay