Using java to send/receive different objects through UDP
Posted
by AAA
on Stack Overflow
See other posts from Stack Overflow
or by AAA
Published on 2010-05-29T14:12:51Z
Indexed on
2010/05/29
14:22 UTC
Read the original article
Hit count: 323
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
© Stack Overflow or respective owner