[英]Socket.io in laravel 5 for chat
So i have a script using socket io, a node.js server and a redis queue for a live chat in laravel 所以我有一个使用套接字io,node.js服务器和Redis队列的脚本,用于在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 我一切正常,redis队列正在接受输入,当我使用“ redis-cli monitor”时可以看到它,但是消息arent正在输出到套接字视图中
The socket.blade.php 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 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 任何帮助表示赞赏
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! 然后,我检查了与socket.io的客户端连接,并将连接更改为节点服务器从http:// localhost运行的VM的IP,它工作得很好!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.