Sorry for the spam of comments:
I can view it on a different port, if I manually go to http://127.0.0.1:3000/socket.io/socket.io.js but on my server http://127.0.0.1:8000 it can't find it? And thats the error.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Sorry for the spam of comments:
I can view it on a different port, if I manually go to http://127.0.0.1:3000/socket.io/socket.io.js but on my server http://127.0.0.1:8000 it can't find it? And thats the error.
In Node Socket Event is broadcasting but in blade file socket is not listening this emitted event
** socket.js file ** `io.emit(channel, message.data);'
welcome.blade.php file
socket.on("test-channel", function(message){ console.log(message); $('#power').text(parseInt($('#power').text()) + parseInt(message.data.power)); });
I tried this tutorial on a fresh install of laravel 5.6 with socket io 2.1.1, and while the socket server runs fine, and connects in the "test" browser window. But nothing ever shows in the socket from running the "fire" window. Can someone share their working version of this in a GitHub project?
I put mine onto here, maybe someone can see the problem and fix so everyone in the future can have a compiled version of the demo
Public repo I'll leave for others to benefit from :
https://github.com/PinDrops/laravel-chat-demo
Request URL: http://localhost:3000/socket.io/?EIO=3&transport=polling&t=MFwFvNR
response:
96:0{"sid":"NJGWx-qXUfgRIAiSAAAB","upgrades":["websocket"],"pingInterval":25000,"pingTimeout":5000}2:40
are those 96:0 and 2:40 supposed to exist? seems like a debugging error is somewhere.
Request URL: http://localhost:3000/socket.io/?EIO=3&transport=polling&t=MFwFvNh&sid=NJGWx-qXUfgRIAiSAAAB
response:
1:6
Request URL: ws://localhost:3000/socket.io/?EIO=3&transport=websocket&sid=NJGWx-qXUfgRIAiSAAAB
results of the frames are:
2probe
3probe
5
3
2
...
socket.js
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var Redis = require('ioredis');
var redis = new Redis();
redis.subscribe('test-channel', function(err, count) {
});
redis.on('message', function(channel, message) {
console.log('Message Recieved: ' + message);
message = JSON.parse(message);
io.emit(channel + ':' + message.event, message.data);
});
http.listen(3000, function(){
console.log('Listening on Port 3000');
});
test page
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.1.1/socket.io.dev.js"></script>
<script>
var socket = io('http://localhost:3000');
socket.on("test-channel:App\Events\EventName", function(message){
console.log(message);
// increase the power everytime we load test route
$('#power').text(parseInt($('#power').text()) + parseInt(message.data.power));
});
</script>
the console.log never executes
Route::get('fire', function () {
// this fires the event
$ev= event(new App\Events\EventName());
var_dump($ev);
return "event fired";
});
var dump result is always an empty array
$ node socket.js
Listening on Port 3000
thanks!
awesome!!!
someone apply this in laravel 5.5?
@JOHNRIVS - Hi sir can I ask a help?
@MSTNORRIS - Good day sir, In Laravel 5.6 should I still make a socket.js? or I should put the below code in bootsrap.js
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var Redis = require('ioredis');
var redis = new Redis();
redis.subscribe('test-channel', function(err, count) {
});
redis.on('message', function(channel, message) {
console.log('Message Recieved: ' + message);
message = JSON.parse(message);
io.emit(channel + ':' + message.event, message.data);
});
http.listen(3000, function(){
console.log('Listening on Port 3000');
});
I tried to make a real time notification using Laravel echo, redis adn socket.io..
I followed the docu although I get notified but I need to refresh the page first to pop-up new notification in my icon...
need some help.
@BOBBYBOUWMANN - Hi sir, Saw your name in comment... I need some help about this https://laracasts.com/discuss/channels/laravel/how-to-listen-laravel-broadcast-notification... My notification doesn't change for new notification.
Getting this response please help. I'm on windows. Redis is started in services.
Message Received: undefined {"event":"App\Events\EventName","data":{"data":{"power":"10"},"socket":null},"socket":null}
When I run /fire route, I have the following log
Broadcasting [App\Events\EventName] on channels [test-channel] with payload: { "socket": null }
And it's still on /test route 0 show. I use Larval 5.5
Thank
Hi I have used the same code, but i am getting Cross-Origin Request Blocked: error in client side
Please or to participate in this conversation.