would it be a good idea to use RMI for a networked game, or would it be too slow?
I would avoid it and stick with plain old sockets
I would strongly advise against it.
Not only do you suffer from RMI garbage collection, RMI simply isn’t suited for anything realtime.
If you, however, will want to use it, be sure to disable Nagle’s Algorithm, because of the lack of explicit flushing in RMI, you can have serious unexpected multi second delays.
so… say i use an interface with methods like update(int x, int y, int z, int frame) and
damage(int damage) using only primitives, so serialization is not needed, will it go reasonably fast?
or should i just send messages like that over a socket?
Use DataInputStream & DataOutputStream, it surely is much better to understand the underlying technologies and their characteristics, before you go highlevel with RMI or its alternatives.
I even use human readable messages when i am developing net code. I can switch between debug human readable and, binary compressed even in release versions. Being able to see things with tools like tcpdump is invaluable.
I would also advise starting with a human readable protocol: plain text. Line separated protocols probably work best. Almost the entire internet runs on these ‘legacy’ easy to debug protocols.
I’m so used to getting criticism for it, with people advising really highlevel network APIs, that I didn’t bother.
But just like you do the occasional System.out.println() or draw a few debug shapes in your UI, it’s best to have a way to visualize your network traffic. Looking at binary doesn’t really help.
When I’m using KryoNet, it has debug logging so you can see what classes are being sent. This is generally not enough information to do much debugging. It also has trace logging, so you can see every little step of serialization. This is generally too much information (unless debugging serialization rather than game logic). So what I end up doing is this:
StringWriter stringWriter = new StringWriter();
YamlWriter yamlWriter = new YamlWriter(stringWriter);
yamlWriter.write(message);
yamlWriter.close();
System.out.println(stringWriter);
This uses YamlBeans to dump all the fields on an object as YAML, which is nice and human readable. YamlBeans uses reflection to serialize very similar to KryoNet: handles object graphs, looks at fields the same way, etc. Example output:
[quote]!com.esotericsoftware.arcanetactics.actions.server.CastAction
action: !com.esotericsoftware.arcanetactics.actions.FireballAction
id: 1
characterID: 6
column: 7
row: 3
x: 832
y: 284
!com.esotericsoftware.arcanetactics.actions.server.TimerCancelAction
id: 1
completed: true
!com.esotericsoftware.arcanetactics.actions.server.HealthAction
characterID: 1
effectType: fireball_hit
value: -5
!com.esotericsoftware.arcanetactics.actions.CloakTimer
characterID: 6
[/quote]
Riven’s right. i should just use plain text(or binary and have an option on the server to dump a plaintext translation).
:)Thanks for the help!