LibGDX supports Desktop (Windows, Linux and Mac), Android and web applications. Can i code the network part of an online game without taking care of what kind a of application i'm running? i.e coding the network engine interdependently of the application type.

  • 1
    \$\begingroup\$ I'm not entirely sure what you are asking. When you mean platform independent, do you think of linux, windows and osx. If so, then yeah, you should be able to use the same code (from the same library). The part about javascript in your question confuses me a bit. Are you talking about the libgdx html5 export functionality? Because java is not javascript. Those are two different languages. If you want a good networking API, use KRYONET => code.google.com/p/kryonet . It is very simple to set it up and to work with. \$\endgroup\$ – tom van green Sep 18 '12 at 8:59
  • \$\begingroup\$ @tomvangreen by platform, i mean platform supported by libgdx. Linux/Mac/Windows for desktop applications, android for mobile and html5 for web. My question is: can i use the same code for handle network on both desktop, android and web application using libgdx? About javascript, i though it was used with html5 for the web port by libgdx. I have edited my question, hopefully it's clearer now. \$\endgroup\$ – nathan Sep 18 '12 at 9:20
  • \$\begingroup\$ I'm not sure about web applications... If you run an applet or a java webstart, then you can use the same code... If you export to html 5, then you may need an alternative... To support all platform, the easiest way would be to implement networking with byte arrays (all data is just sent as bytes). I think node.js offers networking functionality for js, so you just have to create a network protocol and implement it in java and javascript. If you leave out html 5, than you can use kryonet for all versions. \$\endgroup\$ – tom van green Sep 18 '12 at 9:25
  • \$\begingroup\$ @tomvangreen i'm more concerned with android/desktop application so yeah i think i'll go with kryonet. You should create an answer. \$\endgroup\$ – nathan Sep 18 '12 at 9:28

If you just want to target desktop and android devices, you can use the same networking library, as long as the library supports android.

Kryonet is a networking library, that works both on desktop and android, and it is very easy to use (just look at the example from the page).

If you want to implement networking also for HTML5 games, you would most likely need a different solution. A way to go could be working only with byte streams/arrays and implement the protocol for both javascript and java. I think Node.js has networking functionality and enables sending and receiving byte streams. This would be a more low level approach to networking, in contrast to the kryonet solution.

| improve this answer | |
  • 1
    \$\begingroup\$ Best way to do real-time networking in HTML5 is using WebSockets, preferably through node.js's socket.io (for fallback technologies and some nice additions). Socket.io allows you to send ordinary js objects and with plain WebSockets you can send them with JSON.stringify(). No need to resort to custom byte streams, unless you want maximum compression of the messages. WebSockets are implemented in other languages too, so the server doesn't have to use node. \$\endgroup\$ – Tapio Sep 19 '12 at 6:11
  • \$\begingroup\$ Kryonet doesn't work on iOS.. \$\endgroup\$ – Oliver Dixon Sep 12 '15 at 8:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.