Sign in to follow this  

Network Protocol

This topic is 4665 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Haha ok i dont know if the Subject is actually relavent to this but i just felt lyk saying that lol. Ok, i've been trying to use ObjectOuput and Input Streams in my game and they are just a hassle, so im changing to DataInput and Output Streams. I have a java.util.Set of bullets (Objects), Thats why i initially used the object output stream and input stream, all i had to do was send the set, and then the server would send the set to the client and the processing could be done over there (getting x and y values out of objects). Hoever now i am using DataOutputStreams. So below ill paste what i think i should do: Client: BEGIN send set.size interator = set.iterator While Iterator has next{ bullet = iterator.next send bullet x send bullet y } END SERVER BEGIN num of bullets = read() while x < numbullets Set.add( read()) Set.add( read()) end while mainserver.sendtoAll END Ok, to tell your the truth something in me just tells me that isnt the way i should be going about it. Thats why i am posting here, i always get good responses. *Note the reason i stoped using OOS and OIS is because of a serialization problem (i think thats wat it was) the oos would realise that it has sent this object before so it would send the object it first sent, not the updated object etc etc lol i ran into many difficulties, and then foundout that DataInputStream is probably more effient anyway? Correct me if im wrong. Im also thinking of Using Datagrams on the server side and using the multicast feature, also using the datagram multicast feature on the client side to listen. I'd still have to use the Socket and the DataOuputStrwam to send data from the client. But would this be a better way of going about this? (Im pretty new to most of this) Cheers, Nick

Share this post


Link to post
Share on other sites
I think you need to worry a little bit about how the data gets where it's going.

For a simple protocol like this, I would define an interface "packToData/unpackFromData" which would serialize the data each entity needed. Then I would loop over all the entities, and for each entity that needs to have an update, add the entity Id to the output packet, then call packToData to get entity-specific data (which would be x,y for the bullet), and coalesce it all into a big packet. Then send the packet in one swell foop, probably preceeded by a packet size (seeing as you're using TCP).

When unpacking, I would read the packet size, and then that much data. I would then read an entity id, find that entity, call its unpackFromData to unpack from the stream, then read another entity Id, repeat until out of data in the packet.

You probably also need to worry about entity creation and deletion in the protocol.

Share this post


Link to post
Share on other sites

This topic is 4665 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this