Hello everyone,
I am writing a program in Java where there are communications between two or more machines using UDP. My application sends objects after serializing them through the network to the other machine where it will be deserialized and dealt with it. I was successful in sending one kind of objects so far.
My problem is that I want the sender to be able to send different kind of objects, and for the receiver to be able to receive them and cast them again to their appropriate types. However, since UDP allocates a byte buffer then receive the data into the buffer, it is impossible to cast or detect the type of the received object as different objects have different sizes.
Is there is a way that I can use to send different kind of objects using UDP and then receive them at the other end? (I don't ask for code here, just some ideas)
Thanks
Edit: I am looking for the best way to send/receive different objects types without knowing what is the type of the next expected object. Say I have three objects types and I expect receiving any of them at any givin time. Another thing which crossed my mind after Brian's comment: How to set the buffer size for variable sized data-types like Strings, Arrays,...etc. As when receiving a UDP packet you have first to allocate a buffer with a size to receive that object. This is somehow related to my original question.