pspeed
December 6, 2021, 12:09pm
41
You have to wait until you are actually connected before you can send a message. The client and the server exchange some data during connection setup.
Don’t send a message until you have the connection event.
Did you look at the chat client and server examples already?
comic
December 6, 2021, 1:56pm
42
looks like I missed this
try {
Thread.sleep(1000); // wait a couple beats to let the messages go out
} catch( InterruptedException e ) {
e.printStackTrace();
}
let me try again when my internet not trouble
pspeed
December 6, 2021, 2:15pm
43
But 1 second may not be long enough.
Best to not start doing your networking until you get notified.
Put your app/networking logic into an app state that gets attached once your ClientStateListener receives the event that says things are fully connected.
Else you will just get random bugs later.
Here is a fully working networking example with everything but “the game” included:
Edit: or the JME chat example already mentioned:
/*
* Copyright (c) 2011-2021 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
This file has been truncated. show original
…though it does nothing special with its ClientStateListener, it could have waited to enable the UI until it got clientConnected.
tlf30
December 6, 2021, 5:40pm
44
Iirc, all messages should register themselves after the connection is established.
If you would like to look at a more robust networking solution for jme, I wrote a library that uses netty.io .
See the wiki in the github repo for documentation on how to use it. There is also an example server and client in the repo as a good reference.
pspeed
December 6, 2021, 6:59pm
45
tlf30:
more robust
Arguable.
That is correct. They only need to be registered on the server.
…which is one of a dozen reasons that you can’t just start blasting messages until the connection is fully connected.
comic
December 7, 2021, 1:50am
46
[Solved] at least by far. thanks.
Started client:com.jme3.network.base.DefaultClient@7e2d773b
Dec 07, 2021 8:47:32 AM com.jme3.network.message.SerializerRegistrationsMessage registerAll
INFO: Registering:Registration[-19 = com.jme3.math.Vector3f, serializer=com.jme3.network.serializing.serializers.Vector3Serializer]
Dec 07, 2021 8:47:32 AM com.jme3.network.message.SerializerRegistrationsMessage registerAll
INFO: Registering:Registration[-41 = com.jme3.network.serializing.serializers.FieldSerializer, serializer=null]
Dec 07, 2021 8:47:32 AM com.jme3.network.message.SerializerRegistrationsMessage registerAll
INFO: Registering:Registration[-43 = [I, serializer=com.jme3.network.serializing.serializers.ArraySerializer]
Dec 07, 2021 8:47:32 AM com.jme3.network.message.SerializerRegistrationsMessage registerAll
INFO: Registering:Registration[-46 = [Lcom.jme3.network.message.SerializerRegistrationsMessage$Registration;, serializer=com.jme3.network.serializing.serializers.ArraySerializer]
Dec 07, 2021 8:47:32 AM com.jme3.network.message.SerializerRegistrationsMessage registerAll
INFO: Registering:Registration[-48 = mygame.HelloMessage, serializer=null]
clientConnected(com.jme3.network.base.DefaultClient@7e2d773b)
Sending:mygame.HelloMessage@2173f6d9
Client #11 received: 'Hello World!'