WebSocket MMO Server: Node.js or C ++?

I was thinking of creating a real-time game with WebSockets for the Internet. I know how to use Node.js, and there is a temptation to do it there. But everywhere I look, C ++ seems to be a popular server language because of its speed.

Should I make it in Node.js a go, and worry about C ++ later, or should I learn C ++ now and make it there from scratch?

+6
source share
2 answers

If you decide to go for the C ++ route (and this ensures the best performance of any language), there is this open source open source library that does all the hard work for you. Its heading only uses only a pinch. It comes with sample code and documentation: http://vinniefalco.imtqy.com/

Here is the complete program that sends a message to the echo server:

#include <beast/websocket.hpp> #include <beast/buffers_debug.hpp> #include <boost/asio.hpp> #include <iostream> #include <string> int main() { // Normal boost::asio setup std::string const host = "echo.websocket.org"; boost::asio::io_service ios; boost::asio::ip::tcp::resolver r(ios); boost::asio::ip::tcp::socket sock(ios); boost::asio::connect(sock, r.resolve(boost::asio::ip::tcp::resolver::query{host, "80"})); using namespace beast::websocket; // WebSocket connect and send message using beast stream<boost::asio::ip::tcp::socket&> ws(sock); ws.handshake(host, "/"); ws.write(boost::asio::buffer("Hello, world!")); // Receive WebSocket message, print and close using beast beast::streambuf sb; opcode op; ws.read(op, sb); ws.close(close_code::normal); std::cout << beast::debug::buffers_to_string(sb.data()) << "\n"; } 
+9
source

The Google V8 engine used for Node.js does an excellent job compiling efficient machine code. Javascript gets good enough performance for games in games, except for the special attention required to collect memory / garbage and this leads to the fact that many native C ++ computer games are converted to browser-based javascript games . (in particular, the humble package launched the "Mozilla Bundle", which had many of these converted JS games, including "AaaaaAAaaaAAAaaAAAAaAAAAA !!!", "FTL", etc.).

Many real-time game servers are created using Node.js along with socket.io. It's easy to get a basic websocket server that works with node and socket.io so you can quickly prototype the server and do some performance testing to make sure that this is enough for your application.

+5
source

All Articles