Kryonet UDP

I noticed you need to fill in a TCP Port argument when setting up like this Server(TCP Port,UDP Port);
I would like my server to be UDP only since having both increases packet failure.

What’s the problem with just using the UDP writing methods? That way you aren’t using TCP.

Wouldn’t you still listen on that port(TCP) for clients?

I suppose you would. But I can’t see how that would be a problem. I think it needs the TCP port for the establishment of the connection. Once established, it’s probably fine to just use UDP. Are there any specific reasons why you don’t want to have that port used?

I was told using TCP and UDP at the same time is bad, so I wanted to use UDP only and build a sort of confirmation layer when sending important packets.

If you’re only using the writing functions for UDP, then you’re just fine.

Well I also need to send chat messages for example which need to be garantueed to deliver. Would I be better of writing a layer on top of UDP or just use both UDP and TCP

A few resources for you:

and the counterpart:

So it really depends. At first I would ask myself if you really (really) need UDP. Like do you have real-time gameplay that should be sync’d over net (internet, in LAN you will still be fine with TCP) ?

Staying with TCP/IP makes your life way easier in most cases, unless your game is a FPS or similar action-based game.

I personally would say if you use the TCP connection just for reliable chat messaging and your game is not heavily based on chat :wink: then you’re just fine mixing a TCP connection with UDP. It always comes down to the data amount you try to transmit, so a chat message every once in a while won’t be a problem. But I guess you will need more reliable messages - everyone does :wink:

You will want to be sure that certain game information messages WILL get through, so you will send more and more messages with TCP and then you end up using UDP only for position synchronization… but I’m drifting off.

So probably best way: think if you really need UDP, and if yes, implement a proper reliable messaging layer. I did it and it works really well actually.

So I went on to just use both of TCP and UDP, thanks for all the responses and information!
The client will send movement packets frequently, as it moves by 2 pixels every step. Same for projectiles.

Sending position updates doesn’t need to be that frequent. However I don’t know how many “steps” are in a second in your case but if it’s over 20, I recommend sending them at 20 Hz or less, and using visual interpolation to make it look smooth.

Alright :slight_smile:
I’m also having a bit of trouble, when I open up 2 clients and login I control the same character ???

Are there two characters (one for each client)? How are you “getting” (getter method or variable) characters?

Also I didn’t notice you said the client would send movement packets, in that case you wouldn’t need interpolation. However interpolation for entity position updates from the server will make it look smoother.

I’m storing the players in a hashmap along with their ID/connection.getID()
Client sends movement packets to server and server sends to other clients.

Fixed it, I think there was an issue because I was using Integer in the hashmap and I would then use connection.getID() for it, but then the 0 slot would be empty and caused me trouble.
I changed the hashmap to use String and just fill in the playername