views:

953

answers:

3

Is it possible to create a real time game with node.js that requires twitch reflexes. How high is the latency? How low can it realistically go?

+5  A: 

It is possible to make a real-time game in node.js as you could with any other language/framework.

The problem here would be what kind of server and client you would use.
Using the http server feature for such game would be a bad idea and very difficult, but you could use the TCP server (now called net server) as you would in any other language.

The client would be on some platform where you can use sockets, like Flash, Java applets or desktop software.

Please notice that even with using a TCP socket server you might have problems with latency for a twitch game, but this is outside the area related to this question and more about games and networking.

PS: You could use web sockets since they should theoretically work like TCP sockets but there isn't yet a good support for them in the current modern browsers.


EDIT:

It seems I haven't explained myself correctly, you can make a browser accessible game like you said, you just need to use a protocol that allows you to quickly send data back and forth in real time.

If you want a "pure" browser game without any third party plugins the only way, like I said before, is using JavaScript with websockets which is not well supported yet by the major browsers. (You could use a Flash bridge and still have your game in JavaScript though.)

Using a third party plugin you have Flash and Java (besides the numerous less known plugins like unity and so on). Both have TCP sockets (not sure about UDP) and can be made to connect to a node.js net server (with some security limitations). Most people would say for you to go with Flash since there is a bigger support but Apple doesn't like it so no Flash in iPhone/iPad/iPod Touch or on other miscellaneous mobile devices (that support Java instead).

So yeah... good luck with this.

Maushu
using TCP for a game is not very wise, UDP is the way to go.
Lo'oris
What about mobile games? I admit I was mostly thinking about using http to make browser-accessible games, so is realtime / http out of the question then. At this point I'm committed to using http but can design my game to be less reliant on reflexes if that won't work well.
Mark
+1  A: 

It's possible, but it depends on how much data must be transmitted between server and client and how fast (speaking of latency). Take a look at Sousaball by Creationix, for example.

Also, if you plan to use websockets, take a look at Socket.IO library by learnboost. It uses websockets when available and falls back to comet in other cases.

Kuroki Kaze
A: 

HTTP servers are typically optimised for throughput/bandwidth over latency. node.js is unlikely to be an exception, and HTTP is intrinsically poor for low latency anyway due to the structure of the protocol.

One informal benchmark using node.js supports this, showing latencies of hundreds of milliseconds. By comparison most twitch games support latencies of no more than 30 or 40ms, ideally less.

Therefore I'd recommend dropping the twitch aspect if you can't drop HTTP.

Kylotan