예제 #1
0
    // The backend calls this function to open a socket connection.
    // Once this happens, the game starts.
    public void EstablishConnection()
    {
        io.ResetSettings();

        io.On("connect", (SocketIOEvent e) =>
        {
            Debug.Log("SocketIO Connected.");
        });

        io.Connect();

        io.On("world-init", (SocketIOEvent e) =>
        {
            Debug.Log("World init.");

            // So that the server knows that requests have started
            // being processed.
            io.Emit("client-ready", Convert.ToString(userId));

            Debug.Log("Emitted response.");
        });

        io.On("world-update", (SocketIOEvent e) =>
        {
            WorldUpdate(e.data);
        });
    }