breackzin's Recent Forum Activity

  • Really Nice!

  • rexrainbow, I will be looking your server again this October, trying to understand what is so wrong with my own.

    Could you tell me what yours "console.log('app listening on http://' + addr.address + ':' + addr.port);" show to you in your logs?

    My server works on foreman and I manage to keep my previews connected on it locally, but once I produce the server package and push it to heroku, It logs "app listening on http://0.0.0.0:30801" and I can not manage to connect on it.

    Also, some "code=H12 desc="Request timeout"" appears on my logs.

  • Tried it myself without success, so here I am.

    <font color=red><font size="5">U$ 5,00</font></font>

    for the first to deliver a related code(containing the same info present in this one) hosted and working online:

    var entities = [], count = 0;

    var port = process.env.VCAP_APP_PORT || 5000;

    var io = require("socket.io").listen(port);

    var usernames = {};

    var chat = {};

    var rooms = ['room1','room2','room3'];

    var INITIAL_X = 6000;

    var INITIAL_Y = 5000;

    var INITIAL_VEL_X = 0;

    var INITIAL_VEL_Y = 0;

    // assuming io is the Socket.IO server object

    io.configure(function () {

    io.set("transports", ["xhr-polling"]);

    io.set("polling duration", 10);

    io.set('log level', 1);

    console.log("The listening port is:" + port)

    });

    io.sockets.on("connection", function (socket) {

        var myNumber = count++;

        //assign number    

        var mySelf = entities[myNumber] = [myNumber, INITIAL_X, INITIAL_Y, INITIAL_VEL_X, INITIAL_VEL_Y, usernames];

        //Send the initial position and ID to connecting player

    console.log(myNumber + ' sent: ' + 'I,' + mySelf[0] + ',' + mySelf[1] + ',' + mySelf[2]);

        socket.send('I,' + mySelf[0] + ',' + mySelf[1] + ',' + mySelf[2]);

        // Join room

         socket.join('room1');

         // store the room name in the socket session for this client

         socket.room = 'room1';

         //Send to conencting client the current state of all the other players

        for (var entity_idx = 0; entity_idx < entities.length; entity_idx++) { //send initial update

            if (entity_idx != myNumber) {

                entity = entities[entity_idx];

                if (typeof (entity) != "undefined" && entity != null) {

                   console.log(myNumber + ' sent: C for ' + entity_idx);

                   socket.send('C,' + entity[0] + ',' + entity[1] + ',' + entity[2]); //send the client that just connected the position of all the other clients

                }   

            }

        }

        //create new entity in all clients    

        socket.broadcast.emit("message",'C,' + mySelf[0] + ',' + mySelf[1] + ',' + mySelf[2]);

        socket.on("message", function (data) {

           

            //if (myNumber == 0)

            //    console.log(myNumber + ' sent: ' +data);

            var new_data = data.split(',');

            if (new_data[0] == 'UM') {

                mySelf[1] = new_data[1];

                mySelf[2] = new_data[2];

                mySelf[3] = new_data[3];

                mySelf[4] = new_data[4];

                mySelf[5] = new_data[5];

                mySelf[6] = new_data[6];

                mySelf[7] = new_data[7];

                //Update all the other clients about my update

                socket.broadcast.emit("message",

                   'UM,' + mySelf[0] + ',' + mySelf[1] + ',' + mySelf[2] + ',' + mySelf[3] + ',' + mySelf[4] + ',' + mySelf[5] + ',' + mySelf[6] + ',' + mySelf[7]);

            }

            else if (new_data[0] == 'adduser') { // a adduser message

                var usernames = {};

                usernames[0] = new_data[1];

                console.log("message",'adduser,' + mySelf[0] + ',' + usernames[0]);

                socket.broadcast.emit("message",

                   'adduser,' + mySelf[0] + ',' + usernames[0]);

                   }

              else if (new_data[0] == 'chat') { // a chat message

                var chat = {};

                chat[0] = new_data[1];

                console.log("message",'chat,' + mySelf[0] + ',' + chat[0]);

                socket.broadcast.emit("message",

                   'chat,' + mySelf[0] + ',' + chat[0]);

                   }<font size="5">...</font>

           

  • Bumping for a Assistance!

  • vladoss

    broadcast Sends the message or event to every connected user in the current namespace, except to your self.

    It is useful to get off some "picks" from your client code.

    send, sends to everyone but does not support custom events.

    emit, does support.

    Also, my problem is here: scirra.com/forum/socketio-and-heroku_topic71952.html

  • Bumping for the glory!

  • >

    > Every 0,05 seconds:>Send ("alldata," & "," & id & "," & x & "," & y)

    >

    For the server part or a client? I'm a little misunderstood.

    If I will send some kind of data to the server, how can I split it

    Your client. You gonna delete the pick, the "is moving?" condition and put a clear "every 0,05"... as I said.

    The server side gonna be something like this:

    socket.on("message", function (data) {

    var new_data = data.split(',');

            if (new_data[0] == 'alldata') {

                id = new_data[1];

                x = new_data[2];

                y = new_data[3];

                

                socket.broadcast.emit("message",

                  ?'alldata,' + id + ',' + x + ',' + y);

            }

  • You are sending 3 times every 0,01 seconds and that's too much. You don't even need it. Get one 'Send' with all the data that you wanna out.

    You should send this kind of data about every 0,02 seconds max.

    What about a sprite for your player and other for online players? It would help removing that first pick from your code and the 8direction "is moving?", also. You would be able to use the clean:

    Every 0,05 seconds:>Send ("alldata," & "," & id & "," & x & "," & y)

    The second part, the one about managing received data, looks just fine.

    By the way, what language do you speak? Are you deep into socket.io? I have problems myself about hosting it. Could you help me?

    vladoss

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Bumping for wisdom!

  • Get it tested and see for yourself.

  • vladoss

breackzin's avatar

breackzin

Member since 24 Apr, 2013

None one is following breackzin yet!

Trophy Case

  • 11-Year Club
  • Email Verified

Progress

12/44
How to earn trophies