2

GOAL: implement a basic client that can communication to a server from a LibGDX/GWT HTML5/JavaScript deployment. This is for a side-project multiplayer online browser-based game.

WHAT I KNOW AND HAVE DONE: All of my networking experience comes from KryoNet (create a server object, start the server, listen for requests, boom you're done) - can this (or a similar) architecture be achieved in a LibGDX/GWT HTML5 deployment?

After doing hours of research I have yet to have any luck with these magical things called "WebSockets" that everyone says to use. The only "WebSockets" I have found are in Gdx.net and they are "Not implemented".

enter image description here

The following code (that is executed in Libgdxclient-core and gets compiled from Libgdxclient-html)

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Net.Protocol;
import com.badlogic.gdx.net.Socket;


import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Net.Protocol;
import com.badlogic.gdx.net.Socket;


public class Client {
    private Socket socket;

    public Client() {
        Gdx.app.log("create()", "connecting.....");
        this.socket = Gdx.net.newClientSocket(Protocol.TCP, "127.168.1.1", 54555, null);
    }
}

Produces this output:

enter image description here

I came across a couple of GitHub repositories with regards to WebSocket implementation, however I'm stumped as to which (if any) of them is actually LibGDX/GWT compatible and could really use a hand as to what I need to read up on to accomplish my goal (I'm looking for a pure Java solution).

VILLAIN bryan
  • 701
  • 5
  • 24
  • Did you ever find out the answer? I want to do sockets in Libgdx for all platforms – Burf2000 Aug 03 '15 at 08:14
  • You should be able to create an implementation with JSNI. This will take some classic Software Engineering, but will be a great exercise for you. – Keldon Alleyne Feb 05 '16 at 18:36

1 Answers1

2

You probably already resolved your problem (or chosen another solution), but it still might be useful for someone.

First of all: sockets in Net implementations are TCP sockets, which are not supported by browsers - hence the empty implementation. Even if you used a third-party GWT web sockets implementation, it would still be incompatible with LibGDX TCP server sockets.

However, you can choose one of many web socket server implementations along with Java-based web socket clients solutions for "standard" LibGDX platforms and GWT web sockets for the web. Common choices for LibGDX applications seem to be:

  • Java WebSockets - server and client implementations. Client can target most regular LibGDX platforms.
  • gwt-websockets - a very simple GWT wrapper of "native" browser web sockets.

These are some additional libraries that I recommend looking into:

  • nv-websocket-client - Android-compatible web socket client.
  • gwt-websockets from realityforge - more complex GWT web sockets wrapper packed with more features.
  • Vert.x - a superb server framework which features web sockets support.
  • gdx-websocket - a common web sockets API for LibGDX application. Uses nv-websocket-client and custom GWT wrappers internally to target most LibGDX platforms. Disclaimer: I am the author.
Czyzby
  • 2,999
  • 1
  • 22
  • 40
  • How robust would you say these websocket implementations are? .. consistent enough to be used in commercial apps that require constant communication? – VILLAIN bryan Jun 28 '16 at 13:39
  • To be honest, I used LibGDX with web sockets only for small, personal projects, and haven't done any considerable benchmarking. Web sockets are basically using TCP, so they suffer the same limitations: unless you're making a turn-based game, [UDP communication would most likely do better](http://www.diffen.com/difference/TCP_vs_UDP). It would be best if you created some simple applications with each web socket library/framework and compare their performance. You can throw in the KryoNet too, so you can compare them with a UDP implementation. – Czyzby Jun 29 '16 at 10:12