game networking help

I have a client and server for a game and I can send string messages perfectly fine. However, I made an enum type for different types of messages and I would like to be able to send the enum type along with my string message somehow. Is this possible and is it worth the effort? I know that I could farily easily send the type as a string and just parse it, but enum seems a bit cleaner to me. I was wondering if I could use the PrintWriter.print(Object) method to achieve this, but I'm not sure how to correctly read the type from the stream once I write it there.

Once I set up my socket, I use the following code to initialize my reader and writer:

PrintWriter out =new PrintWriter(socket.getOutputStream(),true);

BufferedReader in =new BufferedReader(new InputStreamReader(socket.getInputStream()));

Message was edited by:

Japheth

[1009 byte] By [Japhetha] at [2007-11-27 2:59:43]
# 1
Look at ObjectInputStream and ObjectOutputStream and make sure the object def is available on each machine that will be using it.
morgalra at 2007-7-12 3:40:19 > top of Java-index,Other Topics,Java Game Development...
# 2

I'd read about those and thought they were too complicated, but at second glance, they look like just what I need. However, I am still slightly confused. Should I read directly from the objectinputstream without using an inputstreamreader? The java site says that inputstreamreaders are used if I want to read in strings, so I just want to verify this. Also, if I add an object (my enum type) and a string every time I send a message through my socket, do I have to make sure I read them in the same order I printed them to the stream (i.e. if I print with my printwriter and then add the enum type with an objectoutputstream, do I have to first read using an inputstreamreader and then get the type using objectinputstream)? If I do them in reverse order, will it try to give me a type from the string I sent and a string representing the enum type?

Also, to get the objectinputstream from my socket, should I do the following:

ObjectInputStream in = new ObjectInputStream(socket.getInputStream());

I just want to make sure that I understand the general concept here.

Japhetha at 2007-7-12 3:40:19 > top of Java-index,Other Topics,Java Game Development...
# 3
I got everything working smoothly now and thanks for pointing me in the right direction. Sorry for the double post, but I can no longer edit the last one I made.
Japhetha at 2007-7-12 3:40:19 > top of Java-index,Other Topics,Java Game Development...