io.emit
not working
#4485
Answered
by
TechStudent10
TechStudent10
asked this question in
Q&A
-
I am using a Flask SocketIO server (aka a Python SocketIO server) and I am using a React SocketIO client. I'm building a game/website that is essentially a Kahoot! clone. My page code: import { useState, useEffect } from "react";
import io from "socket.io-client";
const socket = io("http://127.0.0.1:5000")
const joinGame = (gamePIN, nickname) => {
console.log("Attempting to join")
socket.emit("join game", {
player_id: Math.random(),
game_id: gamePIN,
nickname: nickname
})
console.log("maybe????")
}
socket.connect()
export default function JoinGame(props) {
const [gamePIN, setGamePIN] = useState("");
const [nickname, setNickname] = useState("");
let joined = false;
useEffect(() => {
socket.on("send join game success", (data) => {
if (data.game_id === gamePIN) {
joined = true;
}
console.log(data)
console.log("Success!")
})
}, [socket, joined])
return <div className="join-game">
<p>Game PIN:</p>
<input type="number" value={gamePIN} onChange={(e) => setGamePIN(e.target.value)} />
<p>Nickname:</p>
<input value={nickname} onChange={(e) => setNickname(e.target.value)} />
<button onClick={() => joinGame(gamePIN, nickname)}>Join Game</button>
{joined ? <p>Joined</p> : ""}
</div>
} |
Beta Was this translation helpful? Give feedback.
Answered by
TechStudent10
Oct 2, 2022
Replies: 1 comment 3 replies
-
The error was a specific server-side issue that I now have fixed. |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
TechStudent10
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The error was a specific server-side issue that I now have fixed.