node.js real-time game

前端 未结 3 1326
野的像风
野的像风 2020-12-31 17:08

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?

相关标签:
3条回答
  • 2020-12-31 17:47

    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.

    0 讨论(0)
  • 2020-12-31 18:01

    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.

    EDIT 2:

    Websocket support in browsers is now pretty decent so I recommend it for realtime games if you want to use the browser as a client.

    0 讨论(0)
  • 2020-12-31 18:08

    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.

    0 讨论(0)
提交回复
热议问题