JohnnySheffield's Forum Posts

  • it's even easier than that wall of text i wrote:

    To juantar's example server just add at the right place:

    socket.on('disconnect', function (data) {

         

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

          entities[myNumber] = null;

         

    });

    To capx just add (as sub-event of "is data available?" event):

    http://imgur.com/2YZR6

  • First, when a player connects, server must give him his unique number, or a client must notify server what is his number, and store that number on server somehow (you can make your own list of numbers, or use a socket.id number or you can use constructs sprite ID, or etc. but clients and server must know what that number is).

    So, when connects, client can do something like:

    On connect

         Socket send message ("PLAYER, MYID") // in this case client notifys server what his number is

    Depending on what kind of arhitecture you want, you must code this part yourself, you can do something like this maybe (code is a mess, just for a general idea)

    myNumber = 0;

    var Me = [];

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

         

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

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

           

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

                  

              var myNumber = count++;    

              Me[0]='player'

              Me[1]=new_data[1];

    }

    socket.on('disconnect', function (data) {

              socket.broadcast.emit("message",'D,'+ Me[1]);

              //remove player from the list here somehow; Me[1]=null

                   }

    So, when a player disconnects, you can notify all connected games that a specific player is (D)ead, and what is his ID, so that client can:

    On Message "D"

           Pick instance(ID)

               Destroy

    sorry for the messy post, i'm in a hurry but that's how i'd do it. There is probably much more smarter way for this.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I don't know if anybody will need this, but here you go...

    -iPad GUI PSD (Retina Display)

    -iOS 5 GUI PSD (iPhone 4S)

    -Android GUI PSD (High-Density)

    -Baseline Grid

    -iPhone 4 GUI PSD (Retina Display)

    -iPad GUI PSD

    -iPhone GUI PSD

    -iPhone Sketch Elements AI

    -iPad Sketch Elements AI

    Link

  • When i try simple node.js server everything works fine, so I don't believe that "Send" action does not work correctly.

    Also, when I try your server, i get same behavior as you, except when I close the browser I get the following message:

              

    UnicodeDecodeError: 'ascii' codec can't decode byte 0xff in position 0: ordinal not in range(128)

    then i tried bunch of different examples i found on the web, the best one (which nicely prints all the messages received, but still doesen't work) is here:

    http://stackoverflow.com/questions/2153294/python-example-of-joes-erlang-websocket-example

    so, i believe your current server isn't doing the whole connection/handshake thing properly, and the client and server don't actually connect, although they exchange handshakes.

    (this is interesting read: https://github.com/learnboost/socket.io-spec)

    i would try this:

    http://autobahn.ws/python

    or this:

    https://github.com/Lawouach/WebSocket-for-Python

    or this:

    http://code.google.com/p/pywebsocket/

    and more info here:

    http://en.wikipedia.org/wiki/Comparison_of_WebSocket_implementations

  • OrionPyro

    Python isn't my stronger side but here's my two cents:

    I can successfully connect to my server (however, the "OnConnect" event does not trigger). But whenever I try to send data to my server, nothing happens on serverside (the socket is still receiving).

    Not sure about this, sounds like some server side problem, but need more info. i really dont understand the socket is still receiving part.

    And when I close the browser I test my layout in, the Python Console gets full of :

    Waiting for data...
    Data received :
    
    Waiting for data...
    Data received :
    
    etc...

    Looks like you didn't handle what happens when a client disconnects, so your server stays in a loop (because of while True:), and goes to else part, prints "waiting for data", Data received : ",tmp,

    but tmp is empty.

    I think you should end while loop when a client disconnects.

  • //warning: insomnia rant:

    it nothing compared how much i learned from the community, and socket.io is one of plugins really important and powerful plugins to make construct even more powerful, so i think it's crucial to have it clean and stable as much as possible, and make some pre-made ready-to-use node.js server for the community to use. i think that with good semi-moderate but usable node.js servers on some clouds with good explanations and tutorials will boost the use and knowledge within harmony between construct and node.js and current multiplayer demos/real time usage.

    If you asked me yesterday how constructs plugins are made, i wouldn't had an answer, i spent all my free time in last few months to learn node.js and socket.io and etc, and reading this thread yesterday really inspired me to dive in and stop thinking about modding the plugin and just doing it. It was a really a meditative experience, a lot of barriers was passed last night. For somebody maybe not a great success but for me definitively a level up and a big sense of pride for making this mod.

    // serious question:

    oh, before i forget, let me repeat my question for everybody using socket.io plugins:

    whats your knowledge on why socket.io won't minify?

    Let solve that thing, i believe it would be a great step forward in making this plugin and a yet another great multiplayer demo as neat as possible!

  • Hi!

    I've added some functionality to socket.io plugin, but please don't use this plugin in production code because it isn't tested, verified, and i'm not even sure that it's in strict ECMA (i've done my best, but it's been a really long night)

    So, before anything, please somebody double-checks this code, for our own safety.

    That said, i've added two new conditions:

    OnEventReceived

    • triggered when your custom event you specified is received

    and

    OnAnyEvent

    • trigered when any event is received (including connect, message, disconect, your custom events etc... )

    one new action:

    Emit

    • emit a custom event through socket. (You must specify which event, and what data to send with that event)

    and one expression:

    LastSocketEvent

    -where you can get last event that was triggered.

    You can check out the great mind-blowing unbelievable test demo with a node server hosted at http://csocket.jit.su/ at:

    https://dl.dropbox.com/u/62601881/csocket/index.html

    and download a zip file with modifed plugin here:

    https://dl.dropbox.com/u/62601881/demo_test.zip

    along with simple example server, package.json and a .capx file in a separate folder.

    Once again:

    I haven't checked is this mod backward compatibile, ECMA strict, or anything, try it, mod it, if you have time, make it better.

    Use at your own risk.

  • i've been following your work for some time now, and your example really inspired me a lot to start digging deeper in Construct and multiplayer stuff.

    I'm a kinda self-taught guy with highschool/college/bussines experience in bunch of different languages (starting in '97 with some good 'ole qbasic and GOTO 10, GOTO 20 stuff), but javascript and node really got my boner up, if you now what i mean, so take my words with a grain of salt.

    So, after reading some of your code on server example, and zack's socket.io plugin and some hacking with it i realized that if we have just a "send" action which calls Socket.send(data), server will always be a giant if loop, and we'll check messages by splitting received data first, then checking how the first part of your message looks like, and i believe it's not really node-ish to do, because when you start writing some bigger pieces your server code is a giant if(like this sentence), which is constantly evaluated and eventually will be slow(er) and hard to understand.

    So i added a "emit" action to the plugin you can emit a custom event to the server. In C2 it is similar to "send", but besides your message, you have to tell it what event are you emitting. Plugin now uses socket.emit('yourevent',"yourdata").

    Now server can, instead of looking like this:

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

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

        if (new_data[0] == 'P') {do something}

          else if (new_data[0] == 'D') {do this}

          else if (new_data[0] == 'L') {do that}

    etc...

    look like

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

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

        etc

    }

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

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

        etc

    }

    and I believe it's much more elegant.

    I planned to post my plugin now, but i've found out you released an updated version few days ago so i'll incorporate my edits to your latest version, and put it here so you can check the code and see have i fucked up anywhere.

    I also started to hack the plugin so you can trigger custom events inside the plugin (so that server can emit custom events to client), but thats a work in progress.

    itza3985: Actually all this motivation for adding emit function is because we're currently working on something similar to your idea. (By we i mean group of 4 people working on this for last 3 months)

    Whole system is made with idea that is reusable for different kind of games, so everyone will be able to connect to our server and implement joystick functionality to your C2 projects. Server is currently hosted on nodejitsu, in my opinion the best Paas currently online (give them a click: http://nodejitsu.com/

    I hope to share a demo with you within next 3 weeks (it's online, but we won't share it until it's on some decent level)

    Taurian with "emit" action you'll be able to utilize the room thingy(although you can do it now with "send" also), but it's something you'll have to do on server side, if i'm wrong somebody correct me, give me some guidance and i'll try to incorporate it in the plugin

    Whoa, enough for now, wrote too much, will report soon with edited plugin and more info on the joystick thingy.

    P.s Has anyone looked into the whole "Socket.io plugin won't minify" thing? In my opinion it's really important to have that problem solved, after i'm done with "emit" thing i'll try put my focus on that!

  • Hi!

    I've been a "lurker" for a year now, just learning, reading and trying to make my business around Construct 2, after a few successfully deployed projects, i feel that i have something to give to this forum.

    In next week or two, i will share my experiences with construct 2 and some projects that i made using this brilliant piece of software.

    I just wanna send a big thank you for whole Scirra team, you are doing a brilliant job, just keep going!