Server not receiving messages

Hi all, I’m working on building a client and server setup for a project idea. The server can send a message to the client, but no messages from the client appear in the server. I have my client, server and shared library of messages as 3 separate projects in IntelliJ and the client and server both have the shared library as a maven dependency. I’m using jME 3.2.4-stable and even tried using 3.3.0-alpha5 with the same issue. Any ideas on how to fix this?

Here’s the server code:

import com.jme3.app.SimpleApplication;
import com.jme3.network.*;
import com.jme3.network.serializing.Serializer;
import com.jme3.network.serializing.serializers.FieldSerializer;
import com.jme3.system.JmeContext;
import com.nexus.arsen.common.messages.SystemMessage;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

public abstract class AbstractConsole extends SimpleApplication {

    private Server consoleConnection;
    private ConnectionListener connectionListener;
    private MessageListener<HostedConnection> hostedConnectionMessageListener;
    protected Map<Integer, HostedConnection> controllers;
    int port = 8888;

    // TODO Hide access to this
    public static void main(String[] args) {
        Console consoleApp = new Console();
        consoleApp.start(JmeContext.Type.Headless);
    }

    // TODO Hide access to this
    @Override
    public void simpleInitApp() {
        System.out.println("simpleInitApp called! Starting network server...");

        try {
            consoleConnection = Network.createServer(port);
            initMessages();
            controllers = new HashMap<>();
            consoleConnection.addConnectionListener(this.connectionListener);
            consoleConnection.addMessageListener(this.hostedConnectionMessageListener);
            consoleConnection.start();
            System.out.println("Network server started at port " + port);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public Server getConsoleConnection() {
        return consoleConnection;
    }

    public void setConnectionListener(ConnectionListener connectionListener) {
        this.connectionListener = connectionListener;
    }

    public void setHostedConnectionMessageListener(MessageListener<HostedConnection> hostedConnectionMessageListener) {
        this.hostedConnectionMessageListener = hostedConnectionMessageListener;
    }

    private void initMessages() {
        Serializer.registerClass(SystemMessage.class, new FieldSerializer());
    }

    public Map<Integer, HostedConnection> getControllers() {
        return controllers;
    }
}

import com.jme3.network.*;
import com.nexus.arsen.common.messages.SystemMessage;

import java.util.Set;

public class DefaultConsole extends AbstractConsole
        implements ConnectionListener, MessageListener<HostedConnection>{

    public DefaultConsole() {
        super();
        super.setConnectionListener(this);
        super.setHostedConnectionMessageListener(this);
    }

    private void welcomeNewConnection(Server server, HostedConnection conn) {
        SystemMessage welcomeMessage = new SystemMessage();
        welcomeMessage.setReliable(false);
        String message = String.format("Weclome %s to the ARSEN Console", conn.getAddress());
        welcomeMessage.setMessage(message);
        server.broadcast(Filters.in(conn), welcomeMessage);
    }

    @Override
    public void connectionAdded(Server server, HostedConnection conn) {
        int totalConnections = getControllers().size();
        Set<String> connAttrs = conn.attributeNames();
        int totalAttrs = connAttrs.size();

        System.out.println("New Connection Detected!");
        System.out.printf("Total connections: %d, connection id: %d, connection address: %s%n",
                totalConnections, conn.getId(), conn.getAddress());
        StringBuffer sb = new StringBuffer("Total Attributes: ")
                .append(totalAttrs)
                .append(" :> ");
        for (String attr: connAttrs) {
            sb.append(attr).append(" ");
        }
        System.out.printf("%s%n", sb.toString());

        getControllers().put(conn.getId(), conn);
        welcomeNewConnection(server, conn);
    }

    @Override
    public void connectionRemoved(Server server, HostedConnection conn) {
        getControllers().remove(conn.getId());
        int totalConnections = getControllers().size();

        System.out.println("Disconnection detected!");
        System.out.printf("Total connections: %d, connection id: %d, connection address: %s%n",
                totalConnections, conn.getId(), conn.getAddress());
    }

    @Override
    public void messageReceived(HostedConnection source, Message m) {
        if (m instanceof SystemMessage) {
            SystemMessage message = (SystemMessage)m;

            String msgBody = String.format("Message from Connection %d: %s.%n", source.getId(), message.getMessage());
            System.out.println(msgBody);
        }
    }
}

The server log:

Oct 04, 2019 12:11:00 AM com.jme3.system.JmeDesktopSystem initialize
INFO: Running on jMonkeyEngine 3.2-stable

  • Branch: HEAD
  • Git Hash: 8291d61
  • Build Date: 2019-07-13
    WARNING: An illegal reflective access operation has occurred
    WARNING: Illegal reflective access by com.jme3.util.ReflectionAllocator (file:/home/kynphlee/.m2/repository/org/jmonkeyengine/jme3-core/3.2.4-stable/jme3-core-3.2.4-stable.jar) to method sun.nio.ch.DirectBuffer.cleaner()
    WARNING: Please consider reporting this to the maintainers of com.jme3.util.ReflectionAllocator
    WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
    WARNING: All illegal access operations will be denied in a future release
    simpleInitApp called! Starting network server…
    Network server started at port 8888
    New Connection Detected!
    Total connections: 1, connection id: 0, connection address: /127.0.0.1:60902
    Total Attributes: 0 :>
    Disconnection detected!
    Total connections: 0, connection id: 0, connection address: null

Here’s the client:

import com.jme3.app.SimpleApplication;
import com.jme3.network.*;
import com.jme3.system.JmeContext;
import com.nexus.arsen.common.messages.SystemMessage;

import java.io.IOException;

public class Controller extends SimpleApplication
        implements ClientStateListener, ErrorListener<Client>, MessageListener<Client> {
    private Client controller;

    public static void main(String[] args) {
        Controller controller = new Controller();
        controller.start(JmeContext.Type.Display);
    }

    public void simpleInitApp() {
        try {
            controller = Network.connectToServer("127.0.0.1", 8888);
            controller.addClientStateListener(this);
            controller.addMessageListener(this);
            controller.addErrorListener(this);
            controller.start();
        } catch (IOException e) {
            System.out.println("No server was found to connect to!");
        }
    }

    @Override
    public void destroy() {
        controller.close();
        super.destroy();
    }

    public void clientConnected(Client c) {
        System.out.println("Client is connected!");
        System.out.println("Game name: " + c.getGameName());
    }

    public void clientDisconnected(Client c, DisconnectInfo info) {
        System.out.println("Client is disconnected!");
    }

    @Override
    public void handleError(Client source, Throwable t) {
        System.out.println(String.format("### ARSEN Thowable ###%n%s%n",t.toString()));
        source.close();
    }

    @Override
    public void messageReceived(Client source, Message m) {
        if (m instanceof SystemMessage) {
            SystemMessage message = (SystemMessage) m;
            System.out.println("From Console:> " + message.getMessage());

            SystemMessage greeting = new SystemMessage();
            greeting.setReliable(false);
            String msg = String.format("Controller %d has established a connection.%n", source.getId());
            greeting.setMessage(msg);
            controller.send(greeting);
        }
    }
}

And the client log:

Oct 03, 2019 11:52:16 PM com.jme3.system.JmeDesktopSystem initialize
INFO: Running on jMonkeyEngine 3.2-stable

  • Branch: HEAD
  • Git Hash: 8291d61
  • Build Date: 2019-07-13
    Oct 03, 2019 11:52:16 PM com.jme3.system.lwjgl.LwjglContext printContextInitInfo
    INFO: LWJGL 3.2.1 build 12 context running on thread main
  • Graphics Adapter: GLFW 3.3.0 X11 GLX EGL clock_gettime evdev shared
    Oct 03, 2019 11:52:17 PM com.jme3.renderer.opengl.GLRenderer loadCapabilitiesCommon
    INFO: OpenGL Renderer Information
  • Vendor: Intel Open Source Technology Center
  • Renderer: Mesa DRI Intel(R) Ivybridge Mobile
  • OpenGL Version: 3.0 Mesa 19.0.8
  • GLSL Version: 1.30
  • Profile: Compatibility
    Oct 03, 2019 11:52:17 PM com.jme3.audio.openal.ALAudioRenderer initOpenAL
    INFO: Audio Renderer Information
  • Device: OpenAL Soft
  • Vendor: OpenAL Community
  • Renderer: OpenAL Soft
  • Version: 1.1 ALSOFT 1.19.1
  • Supported channels: 64
  • ALC extensions: ALC_ENUMERATE_ALL_EXT ALC_ENUMERATION_EXT ALC_EXT_CAPTURE ALC_EXT_DEDICATED ALC_EXT_disconnect ALC_EXT_EFX ALC_EXT_thread_local_context ALC_SOFT_device_clock ALC_SOFT_HRTF ALC_SOFT_loopback ALC_SOFT_output_limiter ALC_SOFT_pause_device
  • AL extensions: AL_EXT_ALAW AL_EXT_BFORMAT AL_EXT_DOUBLE AL_EXT_EXPONENT_DISTANCE AL_EXT_FLOAT32 AL_EXT_IMA4 AL_EXT_LINEAR_DISTANCE AL_EXT_MCFORMATS AL_EXT_MULAW AL_EXT_MULAW_BFORMAT AL_EXT_MULAW_MCFORMATS AL_EXT_OFFSET AL_EXT_source_distance_model AL_EXT_SOURCE_RADIUS AL_EXT_STEREO_ANGLES AL_LOKI_quadriphonic AL_SOFT_block_alignment AL_SOFT_deferred_updates AL_SOFT_direct_channels AL_SOFTX_events AL_SOFTX_filter_gain_ex AL_SOFT_gain_clamp_ex AL_SOFT_loop_points AL_SOFTX_map_buffer AL_SOFT_MSADPCM AL_SOFT_source_latency AL_SOFT_source_length AL_SOFT_source_resampler AL_SOFT_source_spatialize
    Oct 03, 2019 11:52:17 PM com.jme3.audio.openal.ALAudioRenderer initOpenAL
    INFO: Audio effect extension version: 1.0
    Oct 03, 2019 11:52:17 PM com.jme3.audio.openal.ALAudioRenderer initOpenAL
    INFO: Audio max auxiliary sends: 2
    Oct 03, 2019 11:52:18 PM com.jme3.network.message.SerializerRegistrationsMessage registerAll
    INFO: Registering:Registration[-19 = com.jme3.math.Vector3f, serializer=com.jme3.network.serializing.serializers.Vector3Serializer]
    Oct 03, 2019 11:52:18 PM com.jme3.network.message.SerializerRegistrationsMessage registerAll
    INFO: Registering:Registration[-41 = com.jme3.network.serializing.serializers.FieldSerializer, serializer=null]
    Oct 03, 2019 11:52:18 PM com.jme3.network.message.SerializerRegistrationsMessage registerAll
    INFO: Registering:Registration[-43 = [I, serializer=com.jme3.network.serializing.serializers.ArraySerializer]
    Oct 03, 2019 11:52:18 PM com.jme3.network.message.SerializerRegistrationsMessage registerAll
    INFO: Registering:Registration[-46 = [Lcom.jme3.network.message.SerializerRegistrationsMessage$Registration;, serializer=com.jme3.network.serializing.serializers.ArraySerializer]
    Oct 03, 2019 11:52:18 PM com.jme3.network.message.SerializerRegistrationsMessage registerAll
    INFO: Registering:Registration[-48 = com.nexus.arsen.common.messages.SystemMessage, serializer=null]
    From Console:> Weclome /127.0.0.1:60510 to the ARSEN Console
    Client is connected!
    Game name: Unnamed jME3 Game
    Client is disconnected!

Does the test chat client and server work for you?

Edit: also, does it work if you setReliable(true) instead of using UDP?

Hey, sorry for the delay. I tried out the test chat client and server and that worked and I made the edits in my code to follow suit, but I could only get TCP to work. Simply put, when I set ‘message.setReliable()’ to false on the server and/or client, I get

java.lang.RuntimeException: Error deserializing object, class ID:-48

Which I find in my logs as

INFO: Registering:Registration[-48 = com.nexus.arsen.common.messages.SystemMessage, serializer=null]

Yet, everything works fine when ‘message.setReliable()’ is set to true on both ends.

This sounds like a timing problem that should have been fixed by a recent commit. I don’t know if it was in any of the versions that you tried, though.

…which looks like it was in 3.3 alpha5.

Works to. Was gonna make a pr soon to SimEthereal examples removing the Services that you implemented as a temp fix if thats ok.

Yeah, that’s fine. As long as the version dependencies are updated.

Ok, theres some other things I will fix with that so I will do it in two stages.

1 Like

What about gradle version for wrapper?

I’ve left it at the one that I know works. I upgrade my local gradle rarely so I don’t have all of the new dependency types… but stuff should get converted eventually, I guess.

I will leave them as is then.