Hey guys rlly need your hellp

hey guys i was working on 1 project and now i got 1 problem or some of them. rlly need your hellp

var zeroBuffer = new Buffer('00','hex');

module.exports = packet = {

    //params: an array of javascrpt objects to be turned into buffers
: function(params){

        var packetParts = {};
        var packetSize = 0;
            var buffer;

            if(typeof param === 'string'){
                buffer = new Buffer(param, 'utf8');
                buffer = Buffer.concat([buffer, zeroBuffer], buffer.length + 1)
            else if (typeof param === 'number'){
                buffer = new Buffer(2);
                buffer.writeUInt16LE(param, 0);
                    console.log("WARNING: Unknown data type in packet builder!");

            packetSize += buffer.length;


        var dataBuffer = Buffer.concat(packetParts, packetSize);

        var size  = new Buffer(1);
        size.writeUInt8(dataBuffer.length + 1, 0);

        var finalPacket = Buffer.concat([size, dataBuffer], size.length + dataBuffer.length)

        return finalPacket;


var now = require('performance-now');
var _ = require('underscore');

module.exports = function (){

        //these objects will be added at runtime
        //this.socket = {}
        //this.socket = {}

.initiate = function(){
        var client = this;

        //send the connection handshake packet to client.

        console.log('client initiated')
    this.data = function(

And then i start the game it should be shown :

client initiated

but i have got an error

^ TypeError: undefined is not a function     
at c:\Users\...\packet.js:30:25     
at Array.forEach (native)     
at Object.module.exports.packet.build (c:\Users\...\packet.js:14:16)    
at initiate (c:\Users\...\client.js:17:36)     
at Server.<anonymous> (c:\Users\....\server.js:37:16)     
at Server.emit (events.js:107:17)     
at TCP.onconnection (net.js:1303:8)  Process finished with exit code 1

P.S. rlly srry for my terable english. rlly im waiting your hellp guys anyone can hellp me?

1 comment
Comment actions Permalink

I'm not sure if it's the right place for this. Try StackOverflow next time (but be more careful about your english, use the built-in dictionary of your browser).

Anyway, you've defined packetParts as an object but you want an array. Just replace the {} with []:

var packetParts = {};


var packetParts = [];

This kind of mistake should not cause such panic though, be more careful about what you write...


Please sign in to leave a comment.