Problem with connecting nextjs app to laravel echo socket server
Unanswered
Tufted Titmouse posted this in #help-forum
Tufted TitmouseOP
Hello there I hope you are doing well first I am creating chat app with laravel as backend and nextjs as frontend and the socket server run on laravel, the process I want to make is when user send a message nextjs send request to backend and to store the message and after message store it will trigger an event and this time nextjs should be listening to the event,
The problem is nextjs is not connecting to the server although it working it trigger the events I tried to switch to plain react but same thing, don't want to connect, below is my even and controller from laravel and the connection method in nextjs. And thank you for your time.
The problem is nextjs is not connecting to the server although it working it trigger the events I tried to switch to plain react but same thing, don't want to connect, below is my even and controller from laravel and the connection method in nextjs. And thank you for your time.
9 Replies
Tufted TitmouseOP
I got no error so I log them to see what happens with this
echo.connector.socket.on('connect', () => {
console.log('Socket connected:', echo.connector.socket.id);
});
echo.connector.socket.on('disconnect', () => {
console.log('Socket disconnected');
});
echo.connector.socket.on('connect_error', (error) => {
console.error('Socket connection error:', error);
});
echo.connector.socket.on('connect', () => {
console.log('Socket connected:', echo.connector.socket.id);
});
echo.connector.socket.on('disconnect', () => {
console.log('Socket disconnected');
});
echo.connector.socket.on('connect_error', (error) => {
console.error('Socket connection error:', error);
});
Socket connection error: Error: server error
at Socket.onPacket (socket.js:346:33)
at Emitter.emit (index.js:140:20)
at Polling.onPacket (transport.js:107:15)
at callback (polling.js:128:18)
at Array.forEach (<anonymous>)
at Polling.onData (polling.js:131:103)
at Emitter.emit (index.js:140:20)
at Request.onLoad (polling.js:364:18)
at xhr.onreadystatechange (polling.js:300:26)
at Socket.onPacket (socket.js:346:33)
at Emitter.emit (index.js:140:20)
at Polling.onPacket (transport.js:107:15)
at callback (polling.js:128:18)
at Array.forEach (<anonymous>)
at Polling.onData (polling.js:131:103)
at Emitter.emit (index.js:140:20)
at Request.onLoad (polling.js:364:18)
at xhr.onreadystatechange (polling.js:300:26)
That is error I got when I console log them
@Giant panda show us your error logs
Tufted TitmouseOP
. 👆
Tufted TitmouseOP
@Giant panda didn't figure it out?
Tufted TitmouseOP
.
Giant panda
can you share your client side code for socket connection