我正在使用带有redis和socket.io的laravel echo。它存在和私有通道失败
我正在将此软件包用于我的服务器laravel-echo-server
当我使用公共频道时,一切正常,但当我使用私人频道时,错误记录在laravel-echo-server
Client can not be authenticated, got HTTP status 503
⚠ [7:16:00 PM] - 155BcZ4cC_ieweeWAAAD could not be authenticated to presence-chat-message
</style>
</head><body id=ERR_CONNECT_FAIL>
<div id="titles">
<h1>ERROR</h1>
<h2>The requested URL could not be retrieved</h2>
</div>
<hr>
<div id="content">
<p>The following error was encountered while trying to retrieve the URL: <a href ="http://localhost:8000/broadcasting/auth">http://localhost:8000/broadcasting/au th</a></p>
<blockquote id="error">
<p><b>Connection to 127.0.0.1 failed.</b></p>
</blockquote>
<p id="sysmsg">The system returned: <i>(111) Connection refused</i></p>
<p>The remote host or network may be down. Please try the request again.</p>
<p>Your cache administrator is <a href="mailto:webmaster?subject=CacheErrorInfo% 20-%20ERR_CONNECT_FAIL&body=CacheHost%3A%20routingserver-ProLiant-ML10-v2%0D %0AErrPage%3A%20ERR_CONNECT_FAIL%0D%0AErr%3A%20(111)%20Connection%20refused%0D%0 ATimeStamp%3A%20Sat,%2022%20Apr%202017%2013%3A46%3A07%20GMT%0D%0A%0D%0AClientIP% 3A%20172.16.0.69%0D%0AServerIP%3A%20localhost%0D%0A%0D%0AHTTP%20Request%3A%0D%0A POST%20%2Fbroadcasting%2Fauth%20HTTP%2F1.1%0AX-CSRF-TOKEN%3A%20vASD32FqeyddyxVxE 2xIEwV59kjxgETldK9cLIXh%0D%0ACookie%3A%20Elgg_install%3Dk67c3s96b6ddp8pubp2g6lvt 31%3B%20Elgg%3D5ncfp6re96lj5mron6nrmcjlf4%3B%20PHPSESSID%3Dj92vr9dsqq63o9q9a9q5t bu5q1%3B%20Phpstorm-4bea889c%3D96279c8c-c2d7-4275-8185-4e2526d58f0e%3B%20io%3DmT Kxolc1pbd-AO8CAAAC%3B%20XSRF-TOKEN%3DeyJpdiI6InM0eWxhMFlhYXlBb3BZVTQ5SThhNnc9PSI sInZhbHVlIjoiTFpObHVaZ2RtQzlyd0VvYnJHbVNYaDlsOStkcmxFeHo0SEJFTzlqcE01NTVpMDRyY1B 3blRnN3ZnaHhaQzZLUVRXWWNKTGl3RDVFQWhIQnNlSjBhVEE9PSIsIm1hYyI6ImYzYjI4NjgwY2I3YmZ jOGExNGM1ZjYzOGMwZDc2MzQwNjI5YmE4ZmUzMTJhNmRhMjk4MzkzZDJjMWRiZmM0MzgifQ%253D%253 D%3B%20laravel_session%3DeyJpdiI6ImRsd3RNaWpnVWhDUGdqREgxVlNBeFE9PSIsInZhbHVlIjo iQmxZQXl6bWQyN1dxM3QrZmhSdlRYK0ZxdHNpMFNKNnBXbytQQ1piREJmZWN5VHJDS2JXUXRWcjlkaVQ xRnBxdUdMM093czY5ZGw2S0xyb1NtWUNCbGc9PSIsIm1hYyI6Ijg0MDRjN2Q2MDRjMDYwYTc4MTQyZDU 2MzU3MzZkZTc5NDkzZTM3OWEzMjVhM2MyYmFlZjVhZGQ1YzJkNjliNWUifQ%253D%253D%0D%0AX-Req uested-With%3A%20XMLHttpRequest%0D%0AContent-Type%3A%20application%2Fx-www-form- urlencoded%0D%0AProxy-Authorization%3A%20Basic%20dWVtOjEyMzQ1%0D%0AContent-Lengt h%3A%2034%0D%0AConnection%3A%20close%0D%0AHost%3A%20localhost%3A8000%0D%0A%0D%0A %0D%0A">webmaster</a>.</p>
<br>
</div>
<hr>
<!-- ERR_CONNECT_FAIL -->
</div>
</body></html>
以下是我的app.js,bootstrap.js和laravel-echo-server.json
const app = new Vue({
el: '#app',
data:{
messages:[],
},
mounted:function() {
axios.get('/message/2').then(response =>{
for(i in response.data)
{
this.messages.push(response.data[i]);
}
});
Echo.join('chat-message')
.listen('MessageSentEvent', (data) => {
console.log(data);
});
console.log("Done loading ");
},
methods:{
addMessage(message) {
// console.log(this.messages);
this.messages.push(message);
axios.post("ajax/message/send",message).then(response =>{
});
console.log('Added Message');
}
}
});``
bootstrap.js
import Echo from "laravel-echo"
window.Echo = new Echo({
broadcaster: 'socket.io',
host: 'http://localhost:6001',
});
laravel回波-server.json
{
"authHost": "http://localhost:8000",
"authEndpoint": "/broadcasting/auth",
"clients": [
{
"appId": "c6efc75749e6d774",
"key": "6a0910dcc0073a83d06df25ebc2590dc"
},
{
"appId": "0c35b8cc253e901e",
"key": "0c5c4f54754818ccf2ac0fc3f67809b5"
}
],
"database": "redis",
"databaseConfig": {
"redis": {
"host": "127.0.0.1",
"password": "prince",
"port": "6379"
},
"sqlite": {
"databasePath": "/database/laravel-echo-server.sqlite"
}
},
"devMode": true,
"host": "localhost",
"port": "6001",
"protocol": "http",
"socketio": {},
"sslCertPath": "",
"sslKeyPath": ""
}
答案 0 :(得分:0)
根据laravel-echo-server.json
,您已添加了auth主机路由,因此当您与laravel echo服务器连接时,它会检查auth路由响应以验证授权。
http://localhost:8000//broadcasting/auth
它无效,因此您收到此错误,请创建路由Route::post('broadcastAuth','HomeController@AuthSocket');
检查此repo for socket demo https://github.com/karoys/laravel-echo-server-vuejs
答案 1 :(得分:0)
确保您未在config / app.php中注释 App \ Providers \ BroadcastServiceProvider :: class 。这将自动创建广播身份验证路由