Handling monsters on serverside

I’m trying to handle monster movement on the server within my experimental MMO using libgdx and kryonet. Originally, I had monster movement being handled on the client side(while it was single player), which was easy as all the logic just needed to be within the update() method. However now that I’m trying to migrate the monster movement calculations onto the server so that all clients can see the monsters, how would you go about doing that using kryonet? Unless I’m missing something, kryonet does not have a main “update()” method that continuously runs. What I see with kryonet is that is is able to send and receive packets, however I’m trying to make an independent process run on the server that continuously generates passive walking routes for a monster. Doing so will allow me to send those updated X/Y packets to the clients.

Any suggestions?

Best,
Void

Is there any specific question?
I am doing just that right now in my own game and it works fine.

How are exactly are you running that process within your kryonet server? Are you using an update method within kyronet? I mean that in the most literal sense possible. I have all of the code from my ‘single-player’ version, and wasn’t sure if I should just put it into a while(true) statement within the kryonet start() method, but i wasn’t sure if that was the designated or official method of doing something like that.

You should probably just try what you think might work…
You are aware that Kryo is mostly running in it’s own background thread, right?

Kryonet is not a game engine with its own update methods for you to run your logic. It is merely a networking library for general purposes.

As Drenius said, KN has its own internal update thread that can be started with start() where it continually updates itself, checking for incoming packets and processing them with the received method. It doesn’t do any game related things, only networking.

For your server logic instance, you’ll have to set up some loop that gets updated X times per second where it updates all your logic. After you compute the new positions, create/re-use a packet instance with the correct information and send it via the Kryonet Server instance using sendToAllTCP/UDP().

You could just simply run another thread to handle the monster calcualtion, that would probably be better and more efficient anyways.

Thanks to everyones responses and some other focused google searching, I think I figured out how. You don’t have to initialize threads in Kyronet so in my situation it would suffice to simply call other ‘engine’ methods within the start method, and run it with a while(true) statement. Additionally you would want to put the thread to sleep to run it every X seconds, as chris mentioned above.


public class Server {
    ...

    public void start() {
        ...
        server.bind(port);
        server.start();
        update();
    }

    public void update() {
        while(true) {
            <game logic>
            <send some packets>
            Thread.sleep(100);
        }
    }

    ...
}

Create a new thread that acts as the update loop for the entire server application. Put all of the updating code into that thread and send the monster’s updated positions at the end of the monster’s update.

I’ve got a worker thread for pathfinding, and the server sends the complete path back to the client.