Jump to content

Eureca.io v0.6.4 : NodeJS library for HTML5 multiplayer games


Ezelia
 Share

Recommended Posts

Hello community,

 

I was amazed by the number of positive feedbacks and forks of my tutorial about creating multiplayer game using eureca.io and phaser (original topic available here http://www.html5gamedevs.com/topic/8296-tutorial-creating-a-basic-multiplayer-game-with-phaser-and-eurecaio/

 

We use eureca.io for about two years in internal and client projects, but since now it only supported XHR and websockets which are more than enought for many multiplayer cases, but now that webrtc is becoming more and more popular, I decided to include it in the new release.

 

So what's eureca.io ?

 

eureca is a bidirectional RPC library designed with simplicity in mind.

 

and there is nothing better than some code examples to illustrate how simple it is :)

 

 

This is an eureca server exposing a echo() function

var eurecaServer = new Eureca.Server();eurecaServer.exports.echo = function (msg) {        console.log(msg);}

And this is an eureca.io client calling the server

var eurecaClient = new Eureca.Client({uri:'ws://localhost:8080'});eurecaClient.ready(function (serverProxy) {    //echo() function is executed in the server    serverProxy.echo('hello from client');});

The client can also expose a function

eurecaClient.exports.alert = function(msg) {      alert(msg)}

And server can send an alert to the client when the client connect or when the client call echo

eurecaServer.onConnect(socket) {    var client = socket.clientProxy;    client.alert('Alert from server : I see you just connected');}//now we modify the initial echo functioneurecaServer.exports.echo = function (msg) {        console.log(msg);    var client = this.clientProxy;    client.alert('Alert from server : I see you just called echo()');}

Now suppose the server expose a function which return a result

eurecaServer.exports.add = function (a,  {        return a + b;}

Here is how you call and get back the result in the client side

eurecaClient.ready(function (serverProxy) {    serverProxy.add(5, 10).onReady(function(result) {         console.log('5 + 10 = ', result);    })});

those are only some examples of eureca.io features.

 

 

Other cool features

 - Easy authentication : prevent client from calling server without being authentified with a custom server side function you define

 - Integrates with expressjs

 - Supports all those transport layers : engine.io, sockjs, raw websockets, Faye, Browserchannel and WebRTC!

 - Seamless return results + easy way to return from nested calls

 - Completely free and Open source

 

 

 

A note about

WebRTC is mainly designed for peer to peer communication, but eureca.io use it for client/server communication (thank's to https://github.com/js-platform/node-webrtc)

 

unlike websocket, WebRTC can be used as reliable or unreliable transport layer and this make HUGE difference in multiplayer game developement, because unreliable protocoles are very fast, and in many cases, losing some packets is not problematic for multiplayer games.

 

In the present version there is a limitation, WebRTC server cannot be used on windows (because tha package we rely in do not support windows yet).

Browser side is also limitted to the browsers supporting WebRTC : Firefox, Chrome and Opera (IE do not support WebRTC yet)

 

 

So how can I write a game server if my developpement environnement is on Windows  ?

 

Easy, eureca.io transport switching is transparent to the developper, you only change one configuration parameter in the client and server side.

so you can write your code with any supported transport layer on windows, and switch to WebRTC for production.

 

 

let's take the multiplayer thanks tutorial code, and change it so it support webrtc

 

 

1 - Edit server.js

 

Replace this code

var eurecaServer = new EurecaServer({allow:['setId', 'spawnEnemy', 'kill', 'updateState']});

With this one

var eurecaServer = new EurecaServer({transport:'webrtc', allow:['setId', 'spawnEnemy', 'kill', 'updateState']});

2 - Edit ./js/tanks.js

 

Replace this code

var eurecaClient = new Eureca.Client();

with this one for reliable WebRTC

var eurecaClient = new Eureca.Client({transport:'webrtc'});

or this one for unreliable WebRTC

var eurecaClient = new Eureca.Client({transport:'webrtc', reliable:false, ordered:true, maxRetransmits:1});//you can tweek parameters as you wish

3 - Done ! :)

 

 

Want to build a production environement for your multiplayer game using nodejs ?

here is a tutorial about how to build a self monitored nodejs server : http://ezelia.com/2014/ubuntu-nodejs-varnish-monit-en

 

Licence

Eureca.io is under MIT license, this is one of the less restrictive open source licenses, so use it as you wish .

Fork it modify it, contribute :)

use it in your free or commercial project, there is no restriction as long as you respect the MIT license.

 

 

 

 

Get eureca.io

visit the website http://eureca.io/

or

npm install eureca.io

Documentation

it's still not complete, but a big part is covered, http://eureca.io/doc/

There is also a lot of examples provided with the source code :)

 

 

Source code

https://github.com/Ezelia/eureca.io

 

I'm still working on the documentation of this new release, but I'll try to make a new multiplayer game tutorial using WebRTC as soon as I find some spare time.

 

 

Hope this will help community to build amazing HTML5 multiplayer games :)

 

 

 

Comments and suggestions are welcome.

Link to comment
Share on other sites

Oh, this is nice! I will be using this for my next game.

 

Can I have a websocket and a webRTC connection open at the same time? If so, will they affect each other (mysterious packet loss, etc)?

Are there any other limitations of webRTC I should be aware of when using it as a unreliable and reliable channel of communication? I.e. have noticed any peculiarities when using it yourself in multiplayer games where lag matters?

Link to comment
Share on other sites

  • 2 months later...

Hi @horkoda sorry for the very late reply, for some reason I didn't get notification of post replies on this topic.

 

about your questions, there is absolutely no problem to use websocket and webRTC side by side, (this is btw usually used by WebRTC apps to initialize the connection).
the only thing you'll need here is to create a separate server instance for each, and of course listen on different ports.

 

about WebRTC issues, you can encounter incompatibility issues on old browsers or on some mobile browsers since it's quite new standard.

I encountered some strange connection loss but it was rare, can't say if it's because of unreliability nature of webRTC or something else.

 

if you encounter any problem feel free to open issue on github repository

 

hope it'll help.

Link to comment
Share on other sites

  • 6 months later...

Hi Ezelia,

 

nice job! I use your library for my current project and it works great and easy. thumbs up!

 

One question: how can i get the /eureca.js for the client-side? It seems do generate dynamiclly but in need the "real" file for the cocoonjs compatibility. 

 

Thank you. 

 

Regards,

 

Oleg 

Link to comment
Share on other sites

Hi @blackgames

 

Thank you for using eureca.io, I'm curious to see the game using eureca.io, and very happy to know that it helped you in your game creation.

 

About the /eureca.js file, you can prefix it with the server url : if your game server is mygameserver.com, you can use http://mygameserver.com/eureca.js

or you can open the /eureca.js in your browser, save it, and include it to your cocoonjs package then reference it as a static file.

 

make a test and let me know :)
 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...