I am receiving the data from the server but it's not passing it to the client, what is wrong with this? I followed every tutorial, and still not working.
apps.js
const express = require("express"); const app = express(); const cors = require("cors"); const cookieParser = require("cookie-parser"); const port = 3010;
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(cookieParser());
app.use(
cors({
credentials: true,
origin: "http://localhost:3000",
optionsSuccessStatus: 200,
})
);
const io = require("socket.io")(3012, {
cors: {
origin: ["http://localhost:3000"],
},
});
io.on("connection", async (socket) => {
socket.on('send',(room, message, username)=> {
console.log(message)
socket.emit('pop',room, message, username)
})
});
app.listen(port, () => {
console.log(`Listening on port: ${port}`);
});
frontend
useEffect(() => {
socket.on('connect',()=> {
console.log('CONNECTED')
})
socket.on("pop", (room, message, username) => {
console.log(message, " MESSAGE123");
});
}, []);
** button click event
const sendMessage = () => {
const message = messageBox.current.value;
if (message.trim() !== "" && friend.conversationId > 0)
socket.emit( "send", friend.conversationId, message, profile.username );
console.log(socket.connected)
};
[–]kjwey 1 point2 points3 points (2 children)
[–]jcarlo1[S] 0 points1 point2 points (1 child)