Closed farzadi closed 7 years ago
@farzadi Socket is not connected just after you call Connect() method. It's not blocking call so you have to catch "connect" event. "connect" event means that the connection between with your socket and server's socket is ready to exchange packets.
You can change above code like this manner
static Socket socket; static bool isSocketConnected = false;
void Start() { socket = Socket.connect(_networkUrl); socket.On("connect", () => { isSocketConnected = true; }); StartCoroutine(JoinToGame); }
IEnumerator JoinToGame() { yield return new WaitUntil(() => isSocketConnected ); socket.Emit("joinToGame", RequestForGame(DB._myId, _myRoom).ToString()); }
Thank you worked!
How can we Emit outside Start()? I try all of the ways to emit in other methods but it's not working could you please give me an example this is the way I use socket