开发者

how to design a communicate channel of game server

I am planning to design a game server. I wish it could take a very heavy load, reusable, flexiable, but easy to programming, I want to get a balance of those points.

I decide to use nodejs and redis, the data formate of protocal is JSON, websocket

I have experience of web development, but have no idea of game server development, I notice that game server is very Real-Time, and the message is n开发者_JAVA技巧ot peer to peer, but pub-sub channel,

Does nodejs, redis, JSON is a good choice for design the communicate channel, does websocket support by most browser?

Maybe there are too many questions, the only question is how to design a communicate channel for a game server?


First off, next time use the real node.js Tag, so people actually find your question.

Concerning the actual question, yes Node.js is great for multiplayer Games, especially with WebSockets... but those have been delayed for at least half a year due to recently discovered security problems with mis-configured proxy servers (that's actually not the fault of the WebSockets but everyone and their mom panicked about this).

For details:
http://hacks.mozilla.org/2010/12/websockets-disabled-in-firefox-4/
http://blog.pusherapp.com/2010/12/9/it-s-not-websockets-it-s-your-broken-proxy

In the meantime...

You're left with Flash Sockets as a fall back, if you want games with less than 100ms of lag.

Also, JSON is a bad idea. It's extremely bloated for sending game data, what I did, when I created my first multiplayer game with Node.js, was creating BiSON. This acts like a drop in replacement for JSON, it does not support 100% of JSON's features but it's committed to small size of the encoded data and speed.

So if you're willing top experiment around with WebSockets or for the near future use Flash sockets, then you should check out two of the games I've made:

https://github.com/BonsaiDen/NodeGame-Orbit (Strategy Game á la Eufloria)
https://github.com/BonsaiDen/NodeGame-Shooter (Asteroids / Geometry Wars multipler cross over)

But keep in mind that depending on the kind of your game, you need more than just to send messages around, especially if you want to have lag compensation etc.


For communication channels, I would recommend socket.io, which provides a websockets-like API atop of whatever the browser supports. It falls back to Flash sockets and then to jsonp and long-polling as needed. It's well-supported in Node, and things'll just get better automatically for users as their browsers enable websockets natively.

You can do http requests in less than 100ms -- at home I routinely see ~75ms getting 25K of jquery.min.js from the Google AJAX API servers, and ~25ms to return not-modified -- but it requires careful engineering to be sure. If you have a keepalive connection then you don't have the connection setup overhead (especially important if you're doing SSL to protect user credentials), so it could get even faster.

Even so, I would use socket.io, since it provides a good API as well.


You seem to be under-generalizing a great deal. There certainly are game protocols that are point-to-point, it all depends on the game's design, whether it uses a centralized server or not.

Also, many games use binary protocols, with bitstreams being quite common to conserve bandwidth. JSON is at least a few orders of magnitude from that world, so perhaps you should limit your scope from "games" to something more limited. Here, it seems you're over-generalizing instead.


Websockets aren't supported my most browsers that are on the PCs of endusers. Try to use endlessly-loading iframes over HTTPS (over SSL to avoid stupid proxys that want to fully load the endlessly-loading iframe before passing it on) for receiving data, that's widely supported. For sending, use AJAX requests.

Make the iframe page push lines like this one over http:

<script>newData("...")</script>

If that's too slow for you, use a flash/java applet that does the communication.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜