Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   sending objects over sockets? (http://www.velocityreviews.com/forums/t128008-sending-objects-over-sockets.html)

Don 10-25-2003 08:03 PM

sending objects over sockets?
 
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

Gordon Beaton 10-25-2003 08:35 PM

Re: sending objects over sockets?
 
[ excessive crossposting trimmed ]

On 25 Oct 2003 13:03:06 -0700, Don wrote:
> 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

--
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e

Roedy Green 10-25-2003 08:43 PM

Re: sending objects over sockets?
 
On 25 Oct 2003 13:03:06 -0700, donalmurtagh@yahoo.co.uk (Don) wrote or
quoted :

>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.

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.

Joe 10-25-2003 11:21 PM

Re: sending objects over sockets?
 
In article <2vnlpv8tvn92kgkpl9m59r1g3lqqa6o417@4ax.com>,
roedy@seewebsite.com says...
> 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.




--

"It is impossible to be unjust or unfair to the rich and powerful"
-- Harry Britt

Roedy Green 10-26-2003 02:18 AM

Re: sending objects over sockets?
 
On Sat, 25 Oct 2003 16:21:36 -0700, Joe <sfjoe@spamcop.net> wrote or
quoted :

>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.


--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.


All times are GMT. The time now is 01:02 PM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57