examples/game/lib/server.js
function(buffer){

                    //Deserialize binary data into a JSON object
                    var data = micro.toJSON(buffer);
                    var type = data._type;
                    delete data._type;

                    switch (type)
                    {
                        case "Ping" :
                            var numPings = data.timestamps.length;

                            //Ping a minimum of number of times, before calculating the latency
                            if (numPings < MAX_PINGS){
                                ping(data);
                            }
                            else if (numPings == MAX_PINGS){
                                //Calculate this connections average latency and send it to the client
                                data.latency = calculateLatency(data.timestamps);
                                console.log(data.latency);
                                ping(data);

                                //If we haven't initialized yet, add this connection to the server zone
                                if (!initialized){
                                    serverZone.add(connection);
                                    initialized = true;
                                }
                            }

                            break;

                        case "PlayerUpdate":
                            //Set the player update id to the connection id to prevent clients from updating other players
                            data.id = connection.id;
                            serverZone.updatePlayer(data);
                            break;

                        default:
                            console.warn("Unexpected Schema Type Received: "+type);
                            break;
                    }
                }
function(buffer){

                    //Deserialize binary data into a JSON object
                    var data = micro.toJSON(buffer);
                    var type = data._type;
                    delete data._type;

                    switch (type)
                    {
                        case "Ping" :
                            var numPings = data.timestamps.length;

                            //Ping a minimum of number of times, before calculating the latency
                            if (numPings < MAX_PINGS){
                                ping(data);
                            }
                            else if (numPings == MAX_PINGS){
                                //Calculate this connections average latency and send it to the client
                                data.latency = calculateLatency(data.timestamps);
                                console.log(data.latency);
                                ping(data);

                                //If we haven't initialized yet, add this connection to the server zone
                                if (!initialized){
                                    serverZone.add(connection);
                                    initialized = true;
                                }
                            }

                            break;

                        case "PlayerUpdate":
                            //Set the player update id to the connection id to prevent clients from updating other players
                            data.id = connection.id;
                            serverZone.updatePlayer(data);
                            break;

                        default:
                            console.warn("Unexpected Schema Type Received: "+type);
                            break;
                    }
                }
function ( buffer ) { //Deserialize binary data into a JSON object var data = micro . toJSON ( buffer ) ; var type = data . _type ; delete data . _type ; switch ( type ) { case "Ping" : var numPings = data . timestamps . length ; //Ping a minimum of number of times, before calculating the latency if ( numPings < MAX_PINGS ) { ping ( data ) ; } else if ( numPings == MAX_PINGS ) { //Calculate this connections average latency and send it to the client data . latency = calculateLatency ( data . timestamps ) ; console . log ( data . latency ) ; ping ( data ) ; //If we haven't initialized yet, add this connection to the server zone if ( ! initialized ) { serverZone . add ( connection ) ; initialized = true ; } } break ; case "PlayerUpdate" : //Set the player update id to the connection id to prevent clients from updating other players data . id = connection . id ; serverZone . updatePlayer ( data ) ; break ; default : console . warn ( "Unexpected Schema Type Received: " + type ) ; break ; } }
Parse client sent binary data buffer
Parse client sent binary data buffer