Networking woes

As hinted, you either have two versions of your server running or something is already running on the server port that you’ve picked.

Even on windows:
netstat -a

…in a command line will tell you all of the locally open ports. Though it won’t really tell you who has them open.

Thanks. Yeah, I got it… my system is basically working now. Couldn’t have done it without you guys. Once it’s worth showing off a tad, I’ll see if I can post it on here.

So, I want to create a new player object every time a player logs on. When I do so, it throws an error:

SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
java.lang.IllegalStateException: Scene graph is not properly updated for rendering.
State was changed after rootNode.updateGeometricState() call.
Make sure you do not modify the scene from another thread!
Problem spatial name: Root Node
at com.jme3.scene.Spatial.checkCulling(Spatial.java:260)
at com.jme3.renderer.RenderManager.renderSubScene(RenderManager.java:647)
at com.jme3.renderer.RenderManager.renderScene(RenderManager.java:640)
at com.jme3.renderer.RenderManager.renderViewPort(RenderManager.java:974)
at com.jme3.renderer.RenderManager.render(RenderManager.java:1029)
at com.jme3.app.SimpleApplication.update(SimpleApplication.java:252)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:151)
at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:185)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:228)
at java.lang.Thread.run(Thread.java:744)

This is the code I have inside the client’s message listener.
[java]
if (message instanceof NewPlayerMessage)//If the message received is a new player message,…
{
NewPlayerMessage instructions = (NewPlayerMessage) message;//…translate the generic message into a new player message so that functions may be called,…
playerObject newPlayer = new playerObject();//…create a new playerObject (Which extends node and has playerLocation and playerName variables, along with getters and setters.),…
newPlayer.setPlayerName(instructions. getName());//…set the newPlayer name to one derived from the message,…
newPlayer.setPlayerLocation(“entry_point”);//…set an ID to one derived from the message,…

            Sphere mesh = new Sphere(32, 32, 10);//...create a blob,...
            Geometry geom = new Geometry("A shape", mesh); // ...wrap shape into geometry,...
            Material mat = new Material(assetManager, "Common/MatDefs/Misc/ShowNormals.j3md");   // ...give it a material,...
            geom.setMaterial(mat); 
            
            newPlayer.attachChild(geom);//...attach the blob to the new player,...
            rootNode.attachChild(newPlayer); //...and attach the new player to the root node.
            newPlayer.setLocalTranslation(new Vector3f(0, 10, 0));
            
            
            players.add(newPlayer);//add the new player to an arraylist.
            
            
            System.out.println("new player");
        }[/java] 

When I comment out adding the player to the root node, the error does not fire, but I don’t get a blob in my scene. As I understand it, in order to create anything visible it has to be added to one of several nodes: the root node, the GUI node, etc. What causes this error to be fired? I read something about message listeners not interacting with the scene. Is this the problem? Would writing a function that is not a listener, then calling it from the listener work?

The network messages come in on another thread, enqueue your calls properly to the render thread (see the multithreading documentation, press F1 in the SDK to open the manual).

This is waaaay over my head. Is there a simpler (perhaps slower, or less efficient, but simpler) way to do this?

@ulfgur said: This is waaaay over my head. Is there a simpler (perhaps slower, or less efficient, but simpler) way to do this?

No

Curses. OK, I’ll try to learn it.

@ulfgur said: This is waaaay over my head. Is there a simpler (perhaps slower, or less efficient, but simpler) way to do this?

Singleplayer

OK, I’m having quite a bit of trouble with this. If it’s all right, i’m going to re-build the example code and run it by you, to see if I’m understanding.

If I’m totally missing the mark, is there a good tutorial somewhere I could spend some time with?

[java]
//creates a new instance of the class scheduledthreadpoolexecutor. This class juggles different tasks that cannot
//be handled in the main flow of logic.
ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(4);

import com.jme3.material.Material;
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Sphere;

//I declare this somewhere in the document.
//it basically
Future future = null;

//this is the code to stick in the simpleUpdate loop–the central thread…
try
{
//If we need to create a new NPC, and one is not already being created,…
if((needToCreateNewPlayer)&&(future == null))
{
//OK, somehow this starts a thread… It sets the future
//to the executor starting a thread.
future = executor.submit(newPlayer);
Player obj;//create an object for when the thread is done.
}
//If we have started a callable (thread) already, we check the status
else if(future != null)
{
//Get the waylist when its done
if(future.isDone())
{
obj = future.get();//set the new player to whatever the thread returned.
future = null;//reset the future to be used again later.
}
else if(future.isCancelled())//if something didn’t work,…
{
//reset the future to be used again later.
future = null;
}
}
}
catch(Exception e)
{
Exceptions.printStackTrace(e);
}
if(obj != null)
{

    rootNode.attachChild(obj); //attach my new object to the scene,
    players.add(obj);//add the new object to an arrayList (not shown)
    obj.setLocalTranslation(new Vector3f(0, 10, 0));//move the object to the start point.
}

}

// A self-contained time-intensive task:
//note: for this example, Player is an object that extends a node.
private Callable<Player> newPlayer = new Callable<Player>()
{
public Player call() throws Exception
{
//create a new player node
Player newPlayer = new Player();

            //attach a sphere, geometry, material, etc.
            Sphere mesh = new Sphere(32, 32, 10);
            Geometry geom = new Geometry("A shape", mesh);
            Material mat = new Material(assetManager, "Common/MatDefs/Misc/ShowNormals.j3md");
            geom.setMaterial(mat);
            newPlayer.attachChild(geom);   
            
            //shunt the player back to the simpleUpdate loop.
            return newPlayer;
}

};

[/java]

@Empire Phoenix said: Singleplayer
lol, sorry. Can't go that route. ^_^

The first example on that page, you need nothing more, you just need to enqueue the call to the update loop. No executor. No futures, no nothing.

So I stick this:

[appname].enqueue([class name]);

In my initSimplApp ?

Like this: app.enqueue(ClientHandler); ?
At what point is something complicated enough to need executors and futures and stuff?

No, as in the first code example on that page!

[java] mainApp.enqueue(new Callable() {
public Void call() throws Exception {
// DO STUFF HERE
return null;
}
});
[/java]

As was suggested, maybe it makes more sense to learn programming in java before writing a game.

…searching… found it.

OK, I think I’m beginning to understand. I’ve got the callable basically put together, but cannot seem to reference the mainApp.
I assume this is the thing I declared here:?
[java]public static void main(String args)
{
Main app = new Main();…[/java]

@normen said: As was suggested, maybe it makes more sense to learn programming in java before writing a game.

It would be arrogant of me to claim I know Java, but I’m passably competent with the basics. It’s not like I’m coming to bug you before I try anything else. I’ve looked at JMonkey documentation on this website, documentation that Sun and Oracle provided, and a massive tome of java stuff. It told me that both networking and multithreading are “beyond the scope of this book”… And honestly, I’m quite surprised I’ve been coming for help this often. I did not expect to need to relearn networking, and did not know that multithreading would be required. Once I get my basic system running, I should not need help so often.

Look, If i’m really offending you, send some links to a tutorial or two. I’ll be happy to go through them. Anyway, isn’t this what forums are for? Helping the incompetent noobs avoid blowing their computers up? Or am I in the wrong place? Is there a “incompetent beginners” forum this thread should be moved to?

Well don’t get this wrong, we have tons of posts here with over ambitious projects, so ther is a bit of a automatic toxic reaction, nothing personal.

There is a reason networking is said to be around 4-10times harder.
What you could do is just screw a good networking code and use objectstreams + tcp, and patch everything together for a first game. Then after that see the errors and rewrite around 80% of it.(You will do this anyway if you want to have good code)

Thanks. Yeah, believe it or not (I can’t help but maintain a sarcastic tone in writing, for some reason,) I’m not taking it personally. I just concluded that the sheer frequency of my posts must have caused some irritation, and wanted to assert that I’m trying to be as infrequent as possible in my requests for help.

Believe me, when I started this I din’t think it would be this tough. Then again, I’ve done a lot of programming in Flash, which I think does a lot of the complicated stuff for me.

bringing myself back to the topic at hand
So, is MainApp referencing where I create my simpleApplication, or is it talking about a function? The error message that pops up wants me to reference a class, but when I type my classname (Main) in, it rejects it too.

I fail to understand why as suggestion to learn java before you do a game is offensive. You obviosuly have very very few experience in Java, else you wouldn’t ask these questions. I posted a tutorial, you said “Its way over your head”. Well, there you go.

Woah, please slow down. I’m sorry If I gave the impression that I’m offended. I’m not (pg 3, pst 7). I also apologize if I’ve managed to offend you. Not my intent at all.

Like I said, I’m passably competent with the basics of java. Perhaps our perspectives on “basics” are a bit different. My massive tome of java stuff doesn’t even cover multithreading. I can play around with variables, methods, arrays, loops, classes, etc. etc. (pg3, pst5)

When I said it’s “way over my head”, I meant the concept, not the tutorial. I asked if there was a different way of doing things. (a different way, not a different tutorial.) I then proceeded to read and try to understand what was going on. (pg2, pst16) So that I don’t spend a ton of time writing something that has absolutely no chance of working. I’m glad I did; you advised me to follow a totally different route. I was making things way harder than they need to be.

Look, to someone who has been doing this for a while, my questions are indubitably stupid. But isn’t that what forums are for? Helping people with the stupid stuff, so that they can get better, then turn around and help the new noobs with the stupid stuff?