jpdev Posted February 27, 2014 Share Posted February 27, 2014 Last night I installed NodeJS and wanted to see if a multiplayer real time phaser game could work.(Or more to the point, if I could make that work) I think it will be possible. Check out this small proof of concept: http://jppresents.net/test/wstest.html Edit: The test is offline for now. If you move around the stuff on the screen, everybody currently on the page should see it move too.(And you should see their moves.)If nobody is there (quite likely) a second browser tab will do the trick.(although you might not see the dragging animations because phaser stops on losing focus and it will only update when you refocus that browser.) Let me know what you guys think. Is there interest in short tutorial, any questions? Has this been done already, are there tipps and tricks out there? (please post links if possible) My next goal is a multiplayer falling Blocks (see signature for singleplayer version). Teemu-Tor, AlexArroyoDuque, Arlefreak and 1 other 4 Link to comment Share on other sites More sharing options...
jerome Posted February 27, 2014 Share Posted February 27, 2014 What ws lib do you use server-side ? Link to comment Share on other sites More sharing options...
jpdev Posted February 27, 2014 Author Share Posted February 27, 2014 It's https://github.com/einaros/ws on the server side. and this is the code: http://jppresents.net/test/server.js works if you first do "npm install ws" Link to comment Share on other sites More sharing options...
jerome Posted February 27, 2014 Share Posted February 27, 2014 I used to play with this lib and love it :-) If you want to use WS, keep in mind to implement some sessions so your players could share the right game session.You can do that in the ws message (msg.session, msg.typ, etc) or you can use the ws-protocol header (ex : "jpfllblck978583256') although the RFC tells to use only IANA names suffixed by your domain (ex : "xmpp.jppresents.net"). The server won't complain as ws-protocol is just a string and you can write whatever you want : it's your service after all ! Then server-side, you can filter and broadcast browser messages only to their own sessions. You can broadcast messages or send messages to every connected client except the one which just emitted the current message... or only specific clients. It needs a bit more logic though. not sure my english is really clear so far, arf I attended a french academic network conf last december and talk about ... wsIf you can understand some french :video : http://video.renater.fr/jres/2013/index.php?aid=12slides : http://jerome.bousquie.fr/ws_slides.pdfarticle : http://jerome.bousquie.fr/ws_article.pdf But there's plenty of good documentation in english on the Web :-) jpdev 1 Link to comment Share on other sites More sharing options...
jpdev Posted February 27, 2014 Author Share Posted February 27, 2014 Thanks for the input. Session Management is exactly what I'll be looking at next. I am not sure yet how to figure out which client is which. When receiving a message it's easy, I can just place it in the message as you described.I am just not sure .When trying to write down my problem with identifying who to send to, I went over the source again, and I guess I figured it out. My french isn't anywhere near the level that I could listen to tech talks. (15 years ago I nearly failed the class in school .. and haven't used it since) The good news, both our english is good enough to discuss websockets, even though it's a second language to both of us - and our JS seems fine too Link to comment Share on other sites More sharing options...
jerome Posted February 27, 2014 Share Posted February 27, 2014 Thank you :-) I tested many libs (including the famous socket.io) and I used this one for my prototypes : https://github.com/Worlize/WebSocket-NodeIt's as fast as einaros one but it has got a better documentation and give access to more protocol parameters imho.doc : https://github.com/Worlize/WebSocket-Node/wiki/Documentation Here are some tips to manage session or communicate to a very specific connection (client) : https://github.com/Worlize/WebSocket-Node/wiki/How-to:-List-all-connected-sessions-&-Communicating-with-a-specific-session-onlyIt can be easily adapted to einaros. Have fun with WS and JS ! Link to comment Share on other sites More sharing options...
atreliz Posted February 28, 2014 Share Posted February 28, 2014 Hi!!I am actually working on multiplayer games with websockets and I am having problems to hosted them. Most of the free hosting fall down to xhr-polling (using socket.io and node)i notice your game is working fine using real websockets, could you let me know which host are you using? Thanks in advance! Link to comment Share on other sites More sharing options...
jpdev Posted February 28, 2014 Author Share Posted February 28, 2014 Here is a (improvised) playback from the log file as of 40 minutes ago. http://jppresents.net/test/playback.html I actually discovered some stuff I missed "live" .. at arround 1500 .. who was that? Link to comment Share on other sites More sharing options...
zbzzn Posted February 28, 2014 Share Posted February 28, 2014 I am working on a small POC of a server side game (i.e. all the game logic is on the server) with node.js and Phaser See here:https://github.com/BorisKozo/ships Link to comment Share on other sites More sharing options...
jerome Posted March 2, 2014 Share Posted March 2, 2014 Nice work your server side logic seems to broadcast every 16ms which is the common desktop browser framerate... this doesn't guarantee the connected clients will receive the messages every 16ms due to network latency which could differ between clients It's very hard to implement a real synchronized server game engine for all clients especially on the Web.Maybe is it better not to focus on accurate synchronization besides when designing HTML5 games ? Staying on javascript (and nodejs), there are some, more or less complex, game server frameworks if you don't want to reinvent the wheel :https://github.com/NetEase/pomelohttps://www.npmjs.org/package/shellyjshttps://github.com/bonsaiden/maple.jsetc I didn't test any one of these ... Link to comment Share on other sites More sharing options...
xicombd Posted April 14, 2014 Share Posted April 14, 2014 A while ago I did a small test game which uses node and websockets as well. You can try it here: http://xicombd.github.io/phaser-multiplayer-game/public/ And the source code is here: https://github.com/XicoMBD/phaser-multiplayer-game Hope it is useful for someone ClonkMobile 1 Link to comment Share on other sites More sharing options...
axxion Posted July 15, 2014 Share Posted July 15, 2014 thanks xicombd Link to comment Share on other sites More sharing options...
gmalone Posted March 17, 2015 Share Posted March 17, 2015 A while ago I did a small test game which uses node and websockets as well. You can try it here: http://xicombd.github.io/phaser-multiplayer-game/public/ And the source code is here: https://github.com/XicoMBD/phaser-multiplayer-game Hope it is useful for someone Thanks for that clean working example xicombd. Almost a year later, any fresh insights on your approach? Thx. Link to comment Share on other sites More sharing options...
Lotti Posted March 17, 2015 Share Posted March 17, 2015 hello! i'm doing a pong game with phaser, node.js and socket.io... i was wondering two things: 1) how to make phaser not pause the game when the browser loses focus?2) [most important] May i have to drop socket.io in favour of https://github.com/websockets/ws ? i have the dead line on next week and my game is still not running fine on localhost. may i need a faster socket library? does it supports events and rooms like socket.io? Thank you for your time! Link to comment Share on other sites More sharing options...
Recommended Posts