Biggerplay

HTML5 multiplayer ?

Recommended Posts

for those who are using nodejs and want to make client/server communications. I created an RPC library making things simpler : you declare your server and client functions, then the client will be able to call server functions and vice versa .
check it here http://eureca.io/ there is a tchat tutorial on the page showing how to send/receive and "broadcast" messages :)

[Edit] eureca.io uses websockets when available and fallback to other protocols if not (xhr, xhr-polling ...etc)

also for nodejs private/dedicated server, I highly recommand to install varnish in front of nodejs, it'll handle all the static content cache reducing the load of nodejs to only websocket requests, varnish can also do loadbalancing :)




 

Share this post


Link to post
Share on other sites

A bit late to this thread, but wanted to say that, in terms of hosting, I've had a very good experience with nodejitsu, after trying a few alternatives.

 

It's relatively inexpensive (though not free), VERY easy to set up, and importantly it's simple to do slightly more advanced stuff, should you need https or other fancy features. It also takes care of load balancing and scaling for you, to some extent.

Share this post


Link to post
Share on other sites

I highly recommend socket.io and a node.js setup if you're starting out.

 

I wouldn't put any stock in people trashing or praising a programming language in and out of itself... You choose the right tools for the job when you're a programming - you don't stick to something because of a mantra or self imposed rule. 

 

I recommend (and use) node.js for the following:

- Virtually no compilation time, simple dependency management via npm (it's a bit like apt-get/nu-get)

- Fast for prototyping and experimenting

- Easy to find code examples (JS is used for *everything*. Chances are that whatever you need already exists, and someone did it better than you were about to)

- Very low resources use (an EC2 micro-instance can *mostly* do the job if you're not doing realtime movement, definitely fine for early dev). Pretty much any desktop you have can run it.

- There are no gigantic/disgusting IDE's to install

- Huge community and easy access to help

 

I haven't applied these rules to myself yet - but here's an interesting article about optisiming your web games for websockets: http://buildnewgames.com/optimizing-websockets-bandwidth/

Share this post


Link to post
Share on other sites

I haven't applied these rules to myself yet - but here's an interesting article about optisiming your web games for websockets: http://buildnewgames.com/optimizing-websockets-bandwidth/

 

I've implemented abstract interface for sending both binary and json data using the same format. Results were disapointing because js binary functions are extrelemy slow, so packing and unpacking binary values is taking too long for a game. You save some bandwith but it isn't worth it. Check my performance test for simple unpacking 3 values: http://jsperf.com/json-vs-binary-parsing

Share this post


Link to post
Share on other sites

I've implemented abstract interface for sending both binary and json data using the same format. Results were disapointing because js binary functions are extrelemy slow, so packing and unpacking binary values is taking too long for a game. You save some bandwith but it isn't worth it. Check my performance test for simple unpacking 3 values: http://jsperf.com/json-vs-binary-parsing

 

Debatable, in Firefox the binary decode runs *way* faster.

Share this post


Link to post
Share on other sites

Debatable, in Firefox the binary decode runs *way* faster.

yes, I have the same issue, it looks like chrome engine is not using hardware for binary operations and firefox does, while for JSON results are "stable".

And Opera is even better then Firefox.

Share this post


Link to post
Share on other sites

I've implemented abstract interface for sending both binary and json data using the same format. Results were disapointing because js binary functions are extrelemy slow, so packing and unpacking binary values is taking too long for a game. You save some bandwith but it isn't worth it. Check my performance test for simple unpacking 3 values: http://jsperf.com/json-vs-binary-parsing

 

Interesting. I guess at the very least, you could shrink the JSON down. I've been pretty lazy and just thrown shit together so it works :P

 

Here's one really weird thing I found - when calculating world updates, it was faster to spray the updates out individually, as they were processed, instead of queueing them into an array and sending them along a 'heartbeat'. Is this normal? I actually would've expected the opposite. Hope that explanation made sense :P

 

Edit: There was definitely no blocking/lock-ups for processing, everything was processed out of a buffer/queue array.

Share this post


Link to post
Share on other sites

Interesting. I guess at the very least, you could shrink the JSON down. I've been pretty lazy and just thrown shit together so it works :P

 

Here's one really weird thing I found - when calculating world updates, it was faster to spray the updates out individually, as they were processed, instead of queueing them into an array and sending them along a 'heartbeat'. Is this normal? I actually would've expected the opposite. Hope that explanation made sense :P

 

Edit: There was definitely no blocking/lock-ups for processing, everything was processed out of a buffer/queue array.

 

I may be pissing out of the bin here, but: is that delay consistent? Or sometimes happens and sometimes it doesn't?

If not, I'd bet that the problem may be too large packets or delay caused by packet loss.

Share this post


Link to post
Share on other sites

I may be pissing out of the bin here, but: is that delay consistent? Or sometimes happens and sometimes it doesn't?

If not, I'd bet that the problem may be too large packets or delay caused by packet loss.

 

Yep, it was consistent. It was on localhost too so it wouldn't be packet loss/bandwidth spikes or anything like that...

 

One thing I thought of was that maybe the client itself was preferring it - when I say faster I meant the client was more responsive when receiving updates individually and processing them, instead of trying to iterate through an array of updates.

Share this post


Link to post
Share on other sites

when I say faster I meant the client was more responsive when receiving updates individually and processing them, instead of trying to iterate through an array of updates.

 

And that makes sense to me: if you queue updates and try to force the server to proccess them all at once, you are not only delaying the packet but also creating a bottleneck, in this scenario.

Share this post


Link to post
Share on other sites

As I have been also trying to learn how to develop multiplayer games, one thing I have noticed is latency. There will always be some delay in getting messages, so we have to write some prediction mechanism and design user interface such that, the latency is hidden in animations.

Share this post


Link to post
Share on other sites

As I have been also trying to learn how to develop multiplayer games, one thing I have noticed is latency. There will always be some delay in getting messages, so we have to write some prediction mechanism and design user interface such that, the latency is hidden in animations.

 

There are several ways to deal with latency. Two very -very- complete reads I can reccomend are:

 

http://gafferongames.com/networking-for-game-programmers/what-every-programmer-needs-to-know-about-game-networking/

and

http://buildnewgames.com/real-time-multiplayer/

 

('tho I think they've already been suggested at some point in ths thread)

Share this post


Link to post
Share on other sites

This might be slightly off topic, but I have tried making a multiplayer game with node, and I have quit because I couldn't deal with multiple rooms.

What I wanted to have is a different websocket for each room, with only one external port and different url:

 

"ws : //localhost:3000/room1"
"ws : //localhost:3000/room2"

etc...

 

I didn't understand how to open websockets for different paths.

At first I tried to tackle this by opening a new websocket on a new (internal) port everytime I opened a new room, and then proxy the different paths to their port.

 

It worked on my computer as intended, but when I deployed to Heroku or Cloud Foundry (both offering free basic service), it failed because those PaaS's do not permit to open more than one port (the outside port).

 

I asked a question on Stack Overflow on how you open multiple websockets on one port, but no one answered.

http://stackoverflow.com/questions/16409181/nodejs-websocket-routing-based-on-url-without-port-proxying

If you are a Node js genius, please help.

 

Also, you have to make decisions on the architecture of the game's server. If the game is simple, it may be simple, but oh how complicated it gets when you want to have different "rooms"/servers, a "lobby", a website associated with the game, the chat handled along with the game, etc... 

Share this post


Link to post
Share on other sites

You should open one ws service at one port, i.e. 

ws : // localhost : 3333

 and all clients should connect there, whether they connect from room1 or room2.

 

The point is that every port you try to open as websocket is another service, and you need only one service that takes care of everything.

Share this post


Link to post
Share on other sites

Well, I wished to have a few different websockets at the same port, but with a different URL. I'm sure there must be a way to do it. Socket.io permits having multiple sockets each having their URL. (For the game I was making, I used pure WS) Also since I am able to take a websocket update request and proxy it, there should be a way to create sockets without opening ports. Like using streams or something. Now I'm not an expert in websockets or Node Js, but there should be some way. I think it will be more modular to create a separate websocket for each room.

Share this post


Link to post
Share on other sites

Well, I wished to have a few different websockets at the same port, but with a different URL. I'm sure there must be a way to do it. Socket.io permits having multiple sockets each having their URL. (For the game I was making, I used pure WS) Also since I am able to take a websocket update request and proxy it, there should be a way to create sockets without opening ports. Like using streams or something. Now I'm not an expert in websockets or Node Js, but there should be some way. I think it will be more modular to create a separate websocket for each room.

You can open sockets for every url, but you can't open ws service for every url. I don't know how nodejs works exactly, but I'm using python Twisted framework which is widely used as an applications server, and there it works that way. Honestly I can't imagine it other way, I belive you misunderstood something.

Share this post


Link to post
Share on other sites

You can open sockets for every url, but you can't open ws service for every url.

Wait, what are "sockets" in Twisted? In node.js, Socket.io is a library that permits to use websockets in a way that is event based, and that can have different fallbacks if websockets aren't supported. I went to there site, and read that they were "multiplexing" messages to different channels but still using a single websocket. Ok. I see. In Websocket.io you could only send text messages, though.

 

The game I was making used pure websockets to transmit binary data, so having a single websocket for more than one "room" would be complex.

Share this post


Link to post
Share on other sites

Wait, what are "sockets" in Twisted? In node.js, Socket.io is a library that permits to use websockets in a way that is event based, and that can have different fallbacks if websockets aren't supported. I went to there site, and read that they were "multiplexing" messages to different channels but still using a single websocket. Ok. I see. In Websocket.io you could only send text messages, though.

 

The game I was making used pure websockets to transmit binary data, so having a single websocket for more than one "room" would be complex.

 

Having multiple rooms/channels over a single socket is only as complex as your message format. The way socket.io handles that is each message you send is wrapped in socket.io's message format, with your actual data put in there as well. Channels/rooms are just a property of their message format, actually very simple.

Share this post


Link to post
Share on other sites

Wait, what are "sockets" in Twisted? In node.js, Socket.io is a library that permits to use websockets in a way that is event based, and that can have different fallbacks if websockets aren't supported. I went to there site, and read that they were "multiplexing" messages to different channels but still using a single websocket. Ok. I see. In Websocket.io you could only send text messages, though.

 

The game I was making used pure websockets to transmit binary data, so having a single websocket for more than one "room" would be complex.

It works like that: you open server that is listening for websocket connections on given port i.e. 3333. Client from url /room1 connects to your server, server creates socket(channel) for him, then in server callback newChannel is called with this channel as parameter, you have to handle it, most probably you will want to create some object for every created channel and save it in channel_list or whatever. Every created channel has callbacks like onMessage, that is called when client from that channel sends data. You can of course also send data to that channel from server using i.e. channel.send(data). 

If you want server to act differently on every url that client connects from, then client have to send that url to server as message or server can take it from connection header and then you can do what you want with it. But you have to know that client can forge fake header, so you can't trust it, you have to add some additional security checks.

Share this post


Link to post
Share on other sites

There are several ways to deal with latency. Two very -very- complete reads I can reccomend are:

 

http://gafferongames.com/networking-for-game-programmers/what-every-programmer-needs-to-know-about-game-networking/

and

http://buildnewgames.com/real-time-multiplayer/

 

('tho I think they've already been suggested at some point in ths thread)

I am already going through all these articles, I can predict the position of player through some client side prediction but predicting actions is not possible, for e.g. I can predict where the player will be at some time, but ca't predict whether he will change his direction or not and if yes then in which direction or if he is going to jump or not, etc

Share this post


Link to post
Share on other sites

I am already going through all these articles, I can predict the position of player through some client side prediction but predicting actions is not possible, for e.g. I can predict where the player will be at some time, but ca't predict whether he will change his direction or not and if yes then in which direction or if he is going to jump or not, etc

 

And that is about what you can do.. Otherwise you'd be cheating entropy and predicting the future beyond that wich is evident. I'm totally interested in buying stocks from your company if you manage to pull that off :P

 

Ok, ok, sorry for the smart-assery. But really, that's as much as can be accomplished, if that solution is not enough, then there's got to be a problem with the protocols or the networks you are using for the type of game you are trying to make.

Share this post


Link to post
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...

  • Recently Browsing   0 members

    No registered users viewing this page.