[PLUGIN] Zack0Wack0's Socket.io mod

0 favourites
From the Asset Store
Shark.io
$49 USD
Shark.io in the sea full of killer sharks, Sunday of life is the game. Who knows what is happening under the sea?
  • Yep. Thanks~!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You might find an error with

    your-domin.com/socket.io.min.js

    -One way to fix it is-

    1. Move socket.io.min.js from the plugin folder into something like Dropbox.

    2. Change the dependency line in edittime.js

    Note: If you have multiple socket.io plugins one may override the other. Replacing the dependency of both may work but I just deleted the other plugin.

    3. Change the link in runtime.js inside document.write() [line 2] to hte same link you pasted previously.

    Edit: During a compile you may get an error regarding a missing dependency since the project is essentially compiling without it. Just click retry and it shouldn't pop up again until the next time you open the project.

  • If you're using node.js server should automatically serve client socket.io.js file, form the official wiki:

    The client is served automatically by the Node.JS server. In your <head> tag of your HTML, include:

    <script src="http://<uri:port>/socket.io/socket.io.js"></script>

    If your web app and socket.io are on the same server and port, you can simply include:

    <script src="/socket.io/socket.io.js"></script>

    Socket.io client can also include optional version numbers, in order to maximize caching performance. You can simply include the version number within javascript filename;

    <script src="/socket.io/socket.io.v0.0.1.js"></script>

    If you choose to serve the client through other means, you can clone the socket.io-client repository and look at the dist/ subdirectory.

    I'll look into that and change it asap!

    Index

    What server are you using (i mean code-wise, python, node.js etc..)?

    Also, how did you manage to have multiple instances of the plugin? it should be pf_singleglobal?

    Can you specify in more detail what was the actual error?

  • I had chat from Rex and this one. Rex adds the same dependency which overrides any change to this one- for some reason.

    Also, I'm still working on getting things with SSL done. So my setup is a bit annoying lol. I need to try and get multiple instances though. Haven't tried but i will soon.

  • I would like to know, how to try with Juantar's demo?

  • Actually, if you're using node.js, there is no need to have that dependency, your server will serve the client automatically.

    As for multiple instances issue, try to change the id of the plugin and insert multiple instances of the same plugin, each instance with unique id. if that breaks the project, besides renaming the id, try to rename the socket variable in which connection is stored, so you get something like:

    var socket = io.connect('http://localhost/socket')

        , socket2 = io.connect('http://localhost/socket2');

    socket.on('some_event', function () {

        // do something

    });

    socket2.on('other_event', function () {

        // do something

    });

    It should work with juantar's demo, it's pretty much the same plugin, i added some actions and stuff and edited it so it doesn't break when you minify it.

  • Thanks for this great plugin but I'm having trouble understanding the LastData bit.

    Why not present data?

    Consider:

    io.sockets.on('connection', function (client) {

            client.userid = UUID();

            client.emit('onconnection', {id: client.id});

            console.log('\t socket.io:: player ' + client.userid + ' connected');

            client.on('disconnect', function () {

                console.log('\t socket.io:: client disconnected ' + client.userid );

            });

         

    });

    I do a connection, then check if any data is available. If I receive an event named 'onconnection' I spit out the alert with Socket.LastData.

    This comes up as 'websocket' before another alert '[Object] [object]' which is the one I want.

    What is this 'websocket', why do we look one step back in time?

    I must be missing something here!

  • Thanks for this great plugin but I'm having trouble understanding the LastData bit.

    Why not present data?

    Consider:

    io.sockets.on('connection', function (client) {

            client.userid = UUID();

            client.emit('onconnection', {id: client.id});

            console.log('\t socket.io:: player ' + client.userid + ' connected');

            client.on('disconnect', function () {

                console.log('\t socket.io:: client disconnected ' + client.userid );

            });

         

    });

    Is this your server-side code?

    I do a connection, then check if any data is available. If I receive an event named 'onconnection' I spit out the alert with Socket.LastData.

    This comes up as 'websocket' before another alert '[Object] [object]' which is the one I want.

    What is this 'websocket', why do we look one step back in time?

    I must be missing something here!

    Ok, you probably don't want to use the socket.LastData expression, it behaves really strange, and messes up the data... If you read the explanation of the Socket.LastData expression it says:

    (Get the last chunk of data that was received via the socket. (Warning: this exression actually manupalates the data stack, be careful when evaluating it in Construct)

    Meaning: Don't use it!

    What you want to do is:

    On Data ---> Split data received

        ---> Access your data with Socket.LastDataElement(index)

    The "Split data received" Action actually makes the Data.split(','); so it returns an array.

    If you don't want to split the data, and just access the last data recived do the

    On Data ---> Access your data with Socket.LastDataElement(0)

    This is actually the main reason why this plugin isn't the best it can be, it doesen't manipulates recived data on the best possible way.

    Reason for this is that this plugin was originally written by Zack0Wack0, then edited by Juantar, then by some other members, and lastly by me... I added some functionality to it, made it minifiable, but it actually needs an overhaul. A lot of stuff isn't coded the best it could be!

    I'm currently waiting for the socket.io 1.0 to become official, because it makes some serious changes to the Socket.io module and possibly a different API, so probably would be waste of time to overhaul it now!

    I hope i helped,

    Cheers!

  • Thanks a lot for your help, much appreciated.

    (Yes, that was my server code btw).

    I was taking a look at the runtime.js and was thinking if splitting the data by commas was the only way.

    Thanks for the clarification. I was thinking of editing it to work with JSON in the way this article discusses:

    buildnewgames.com/optimizing-websockets-bandwidth

    But maybe for now I will concentrate on using CSV's and working on the client-side predicition and interpolating entities parts of multiplayer:

    gabrielgambetta.com (3 parts)

    I'll get pong up on a server and share to test if we can get acceptable real-time results.

  • Great resources, thanks for sharing!

    My test have shown that with using socket.io i get acceptable real-time results (Acceptable for me), with hosting on nodejitsu (i'm in europe).

    It would be probably better if i'm using my own local server, but that's on the to-do list!

    Also, i'm not sure does it affect the performance, but for my games, i edit the plugin and add my own events to the edittime.js and runtime.js, so i don't have to split data, then compare the first element of array then do some actions. That way, the code looks messy and it's not easy to maintain.

    What i do is add a condition to edittime.js somwhere around line 22 like this:

    AddCondition(5, cf_trigger, "On my event", "My Category", "On My event", "Triggered when my event", "MyEvent");

    To the runtime.js somwhere around line 120:

              socket["on"]

              (

                  ?'MyEvent',

                  ?function(data)

                  ?{

                  ?instance.dataStack.push(data);

                  ?runtime.trigger(pluginProto.cnds.MyEvent,instance);

                  ?}

              );

    and finally add a condition to the condition list around line 265:

         cnds.MyEvent = function()

         {

              return true;

         };

    So i my code looks like:

    On My event ---> DoAction (Split data or not, your choice)

    And not like:

    On Data ---> Split Data

       ---> If LastDataElement(0)="My Event" ---> DoAction

    As for making it work with JSON, maybe look into the following plugins:

    Load JSON

    Hash Table

    And perhaps use them in combination with this plugin!

    Also, if you do some edits to the plugin, i'd be really grateful if you'd share the edits so i can implement them in the plugin, and if you have some test to share that would be great also!

    Cheers!

  • Thanks again Johnny, I will share my progress as it's good for us to advance this concept to a very decent solution.

  • Hey Johnny/all,

    dropbox.com/s/095i4mjtkd9pe2y/socket-io-ace.zip

    Not sure if I should do a new post but I've amended the plugin with the following feature:

    LastDataJSONStringify which works well in combo with the hash table plugin:

    scirra.com/forum/plugin-hash-table_topic47637_post298284.html

    So an example use would be to setup a hash table to store incoming values sent from node such as:

    <img src="http://www.stngame.com/images/hashtbl.PNG" border="0" />

    Then, on an event, populate the hash table with the JSON string:

    <img src="http://www.stngame.com/images/event_cs2.PNG" border="0" />

    You can then access the data using:

    int(OtherPlayerData.AtKeys("y"))

    Server code would look something like:

    this.broadcast.emit("move player", {id: movePlayer.id, x: movePlayer.getX(), y: movePlayer.getY()});

    I'm still working on this so likely to release some more stuff soon...

    Sorry for the short explanation but might as well release often just in case it helps folks :)

  • Whats the most updated "mainstream" version?

  • I would first see will the official websocket plugin suits your needs. if not, there's aceofpack mod, with possibility to send and recieve JSON, but with unstable 'onanyevent' triggers, or my mod, but without json and anyevent. your best bet is to use either version and adapt it to your needs!

    Cheers!

  • I have been working on a design. A Multiplayer Space-Sandbox RPG Game with elements of Real-Time Strategy.

    Using socket.io and your plugin I was able to implement Smooth Movements for players and miners(AIHarvestingDrones). Also I handled the following features:

    Energy

    Shields

    Bullets and Rockets

    Battle(aiming, targeting, seeking)

    Map

    Building

    Harvesting-AI

    Exploring-AI

    Producing Units

    As I was not able to send and receive text, my players have no name but "Player 0,1...". Also, I have built everything updating some old example found here and the example does not handle disconnecting players, so, on connect, a lot of ghosts spawns on new player's screen.

    There are others really minor and easy solving bugs, but they doesn't matter. In the current state, If you guys could help me out I would be able to host my simple "server.js" some place and then start an alpha.

    , that would be a huge burst.

    youtube.com/watch

    Thanks

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)