[KryoNet] How to get the amount of bytes received/sent?

Hello guys, I’m using KryoNet and I wanted to see how many bytes were (Client-side (sent and received)), could anyone tell me how could I achieve that? I’ve looked everywhere but couldn’t find anything. :frowning:

My client-side networking looks like this: http://pastebin.java-gaming.org/67c45649299

I’m creating BMONetwork object in my GameScreen class, in it’s update method I check if the users coordinates have changed and if they did I send them to the server. I guess this is where I should check the amount of data that will be sent?

	public void update(float delta) {
		if (player.getNetworkPosition().x != player.getPosition().x) {
			PacketUpdateX packet1 = new PacketUpdateX();
			packet1.x = player.getPosition().x;
			bmoNetwork.client.sendTCP(packet1);
			player.setNetworkPosition(new Vector2(player.getPosition().x, player.getNetworkPosition().y));
		}
		if (player.getNetworkPosition().y != player.getPosition().y) {
			PacketUpdateY packet2 = new PacketUpdateY();
			packet2.y = player.getPosition().y;
			bmoNetwork.client.sendTCP(packet2);
			player.setNetworkPosition(new Vector2(player.getNetworkPosition().x, player.getPosition().y));
		}
		if (player.getNetworkRotation() != player.getRotation()) {
			PacketUpdateRotation packet3 = new PacketUpdateRotation();
			packet3.rotation = player.getRotation();
			bmoNetwork.client.sendTCP(packet3);
			player.setNetworkRotation(player.getRotation());
		}
	}

If you can help me please provide some code or example how to do it, thanks alot! :stuck_out_tongue:

[quote]If anyone is interested, to get the sent bytes just do something like this:

bytesSent += bmoNetwork.client.sendTCP(packet);

sendTCP(Object object) method returns the bytes sent, so you can just add them up.

http://i.snag.gy/XghgW.jpg
[/quote]

But but but… they have full examples in the website, and you can find the answer with just a little bit of digging around. Here, I’ll give you two very relevant web pages you can scour to get the answer to this…


https://code.google.com/p/kryonet/source/browse/trunk/kryonet/examples/com/esotericsoftware/kryonet/examples/position/PositionClient.java

Thanks, I’ve found a way how to get sent bytes, but I still can’t figure out how to get received bytes. :clue:

Please do not delete and then repost the exact same message in an effort to bump your thread. :slight_smile:

Is it against the rules?

Not really (AFAIK), but it’s mostly pointless (people will see it even without bump) and somewhat annoying, and thus frowned upon I’d say.

Umm okay, wont happen again. Now can someone help me please? ???

How you receive bytes is completely dependent on how you set your server up in the first place. If you don’t have a server that accepts Java code, then you won’t be able to use server side Kyronet. The information given here is so little. What have you tried so far in terms of getting this to work? What kind of server service are you using?

I do have working server which is written in java + using KryoNet.
Server looks like this: http://pastebin.com/0LWrTyGN

But I think you misunderstood my problem, I want to get the amount of bytes the client has received from the server. I think so that this has to be done in BMONetwork received() method but I have no idea how to do that because at that method what is received is a whole object deserialized from the bytes. Everything works fine I just want to keep track of amount of bytes that were received, that’s it.

Sorry for bumping again, but could anyone help me please?

Kyronet is built on top of Java NIO, if you want to figure out how to get packet data down to the bytes, I’d start there. Use the source code to help you track your solution, because your solution lies in Java NIO.

https://code.google.com/p/kryonet/source/browse/trunk/kryonet/src/com/esotericsoftware/kryonet/Client.java?r=122#5

But, the Github page is probably a much better search point… Best of luck. Also, best try not to do too many bumps, as there are hungry monsters running around these parts. :point:

I do think this should be a little easier to do with Kryo tho. Why is it such a chore to do something “that easy” with Kryo, whereas with other Libraries it’s just a matter of saving the return value?