TCP is working, UDP only one way - Kryonet

Hello.

I’m developing an app for android, with a server written in pure Java. When I send TCP or UDP packets from the client to the server - all are being received well.

The problem occurs on the server. When trying to send UDP packet from the srv to my connection, let’s say con1, it’s leaving the server, but never comes to the client.
When changed to con1.sendTCP - it works. What may cause this? Maybe it’s caused by this that I’m sending an array with 32 integers and it’s too big? What do you think?

Thanks!

That packet size is fine. UDP packets can have up to ~65535 bytes in them, and 32 integers is 128 bytes.

EDIT: Show some more code. It’s likely an error in your client setup.

This is strange, cause it should show in the console, that a packet of this type has arrived, but there is no information. It seems that it’s blocked somehow by the router or something.

Tried with all of the packet types - when sent via UDP from the server - it doesn’t get the information - only KeepAlive is showing.

If TCP is normally recognized, the only reason is that UDP packets are being blocked.

The code on the server:

                                      if (object instanceof moveLeftListPCKT){
							moveLeftListPCKT ob = ((moveLeftListPCKT)object);
							
							LinkedList<Integer> received = ob.list;
							for(int i=0;i<received.size();i++){
								
								if(received.get(i) >= player_right.moveLeftSequenceNumber){
									player_right.moveLeft();
									player_right.moveLeftSequenceNumber++;
								}
							}
						
					
							if(player_right.oldMoveLeftPackets.size() > 32){
								player_right.oldMoveLeftPackets.removeFirst();
							}
							player_right.oldMoveLeftPackets.addLast(player_right.opponentsMoveLeftSequenceNumber);
							player_right.opponentsMoveLeftSequenceNumber++;
							
								 	
				            moveOpponentLeft movePCKT = new moveOpponentLeft();
				            movePCKT.list = (LinkedList<Integer>) player_right.oldMoveLeftPackets.clone();
				            System.out.println(player_right.oldMoveLeftPackets);
				            pleft.sendUDP(movePCKT); // we're player left, so we're sending pos to pright

						}

When I change

pleft.sendUDP(movePCKT);

to

pleft.sendTCP(movePCKT); 

it works. How is this possible ?!

I thought that it may be caused by different size of the list every time it’s sent, cause it’s increasing while the program is running, but it won’t exceed 32 ints, so I don’t know…O.o

This is the code from the server - that creates the list. The client is really fine, cause on TCP it’s working perfectly.

Post your client constructor and your usage of the client.connect method.

Just a quick rundown of how Kryonet works (this may be helpful to future readers).

Kryonet has the ability to setup both TCP and UDP connections. The TCP connection is required, but the UDP connection is optional. This means that there are multiple ways to connect a client and server (see method overloading). If you don’t put a UDP port on either end, then only a TCP connection is created, but you don’t get any errors.

However, are you getting errors? Because if I’m right and the UDP connection isn’t setup, then Kryonet will throw errors.

Post your log from the client.

connect() usage:
public static String host = “192.168.1.2”;
public static int tcp_port = 8888, udp_port = 8889;

  @Override
        protected Boolean doInBackground(Void... arg0) {
            try {
                c.client.connect(10000, host, tcp_port, udp_port);
                // Server communication after connection can go here, or in Listener#connected().
            } catch (IOException e) {
                e.printStackTrace();
            }

            if (c.client.isConnected()){
                LoggedIn = true;
                return true;
            }
             else return false;
        }

This is the constructor usage on the client: (it’s just clear - maybe there is a mistake cause on the server I have values).

 client = new Client();
        Network.register(client);
        client.start();

Server:

server = new Server(9000000,9000000)
  • I know that these values are unreal, but it’s just for testing

Everything was running fine since today somehow :frowning:

The only problem is here that when objects are being send from the server to the client via UDP, they don’t arrive (maybe they do, but they’re not complete, broken somehow).

#your edit
I know how this works, already did some things with UDP and they were working…

It’s an Android/Kryo bug - finally, not my fault! :smiley:

Still don’t know how to implement this, changed this method on server & client, but somehow the file is not ‘synchronizing’ and changes are not saving ;(