Reputation: 579
So i have a script using socket io, a node.js server and a redis queue for a live chat in laravel
I have a everything is working and the redis queue is accepting input, i can see it when i use 'redis-cli monitor', however the messages arent being outputted into the socket view
The socket.blade.php
@extends('layouts.admin')
@section('content')
<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-lg10 col-lg-offset-2" >
<div id="messages" ></div>
</div>
</div>
</div>
<script>
var socket = io.connect('http://localhost:8890');
socket.on('message', function (data) {
$( "#messages" ).append( "<p>"+data+"</p>" );
});
</script>
@endsection
socketController.php
<?php
namespace SocialNet\Http\Controllers;
use SocialNet\Http\Requests;
use SocialNet\Http\Controllers\Controller;
use Request;
use LRedis;
class SocketController extends Controller {
public function __construct()
{
$this->middleware('auth');
}
public function index()
{
return view('socket');
}
public function writemessage()
{
return view('writemessage');
}
public function sendMessage(){
$redis = LRedis::connection();
$redis->publish('message', Request::input('message'));
return redirect('writemessage');
}
}
What am i missing here?
Any help appreciated
Upvotes: 0
Views: 1575
Reputation: 579
I checked in my browser console and found that it was a connection refused error. I then checked the client side connection to the socket.io and changed the connection to the IP of the VM that the node server was running on from http://localhost and it worked perfectly!
Upvotes: 1