Back Config
import express from "express";
import SocketIO from "socket.io";
import http from "http";
import cors from "cors";
const app = express();
app.use(cors());
const server = http.createServer(app);
const io = SocketIO(server);
const PORT = 5000;
io.on("connection", (socket) => {
console.log("Connected!!");
socket.on("send_message", (data) => {
console.log('SEND_MESSAGE');
console.log(data);
});
socket.on("disconnect", () => {
console.log("Close.-.--.");
});
});
server.listen(PORT, () => {
console.log(`Server on port => ${PORT}`);
});
Front Implementation
import io from "socket.io-client";
let socket;
const Home = () => {
useEffect(() => {
socket = io("localhost:5000", {
// transports: ["websocket"],
// upgrade: false,
});
return () => socket.disconnect();
}, []);
const onEnter = () => {
socket.emit("send_message", { message: messageToSend });
setMessageToSend("");
};
I receive the Connect and Disconnect emit's but i cant get the send_message emit, HELP! :c, i saw a few videos and courses can't get the result i want, don't judge me, im new with socket io
question from:
https://stackoverflow.com/questions/65877885/socket-io-3-0-dont-receive-emit-on-server 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…