sending objects over sockets?

D

Don

Greetings,

Does anybody know whether it's possible to send object's over a
MulticastSocket(UDP)?

I know it's possible to send a serializable object over a TCP socket,
which can be read via readObject(ObjectInputStream s), and must then
be explicitly cast to the appropriate type. Is it possible to do
something similar with a UDP MulticastSocket? If so, how do you
send/receive the object?

Thanks in advance,

Don
 
G

Gordon Beaton

[ excessive crossposting trimmed ]

Does anybody know whether it's possible to send object's over a
MulticastSocket(UDP)?

I know it's possible to send a serializable object over a TCP
socket, which can be read via readObject(ObjectInputStream s), and
must then be explicitly cast to the appropriate type. Is it possible
to do something similar with a UDP MulticastSocket? If so, how do
you send/receive the object?

For each object, create an ObjectOutputStream wrapped around a
ByteArrayOutputStream. Create a DatagramPacket with the resulting byte
array.

Use a MulticastSocket or DatagramSocket to send and receive datagrams.
Realize that you can use a regular DatagramSocket to send to a
multicast group. You only need to use a MulticastSocket to receive
datagrams sent to the group.

To recreate your objects, create a ByteArrayInputStream and
ObjectInputStream with the array contents of each datagram.

/gordon
 
R

Roedy Green

Is it possible to do
something similar with a UDP MulticastSocket? If so, how do you
send/receive the object?

All you need do is write the object to a byte array. See
http://mindprod.com/fileio.html for how. Then you can bundle that
byte array as your payload in a UDP or Multicast UDP packet. The only
catch is just how long can the packet be? I don't know off the top of
my head how big a UDP packet can be, but I would think it would be in
the order of 128 bytes or so, unless there is some sort of packet
reassembly protocol for jumbo packets now functioning.
 
J

Joe

The only
catch is just how long can the packet be? I don't know off the top of
my head how big a UDP packet can be, but I would think it would be in
the order of 128 bytes or so, unless there is some sort of packet
reassembly protocol for jumbo packets now functioning.


UDP isn't guaranteed to arrive (or am I thinking of something else?). It
might be tricky to reassemble an opbject with missing parts.
 
R

Roedy Green

UDP isn't guaranteed to arrive (or am I thinking of something else?). It
might be tricky to reassemble an opbject with missing parts.

Correct. You could use the same strategies that TCP/IP does with acks,
or you could simply not worry about missing packets because an update
with the same information but fresher will be along soon, e.g. the
state of some other player's game.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top