Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > sending objects over sockets?

Reply
Thread Tools

sending objects over sockets?

 
 
Don
Guest
Posts: n/a
 
      10-25-2003
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
 
Reply With Quote
 
 
 
 
Gordon Beaton
Guest
Posts: n/a
 
      10-25-2003
[ 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
 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      10-25-2003
On 25 Oct 2003 13:03:06 -0700, http://www.velocityreviews.com/forums/(E-Mail Removed) (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.
 
Reply With Quote
 
Joe
Guest
Posts: n/a
 
      10-25-2003
In article <(E-Mail Removed)>,
(E-Mail Removed) 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
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      10-26-2003
On Sat, 25 Oct 2003 16:21:36 -0700, Joe <(E-Mail Removed)> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
VOIP over VPN over TCP over WAP over 3G Theo Markettos UK VOIP 2 02-14-2008 03:27 PM
sending Objects and Strings over TCP/IP Tomek Gruca Java 15 01-16-2007 01:42 PM
Re: sending objects over sockets Knute Johnson Java 5 06-28-2003 03:29 PM
Re: sending objects over sockets Steve Horsley Java 0 06-27-2003 01:51 PM
Re: sending objects over sockets Steve Horsley Java 0 06-27-2003 01:51 PM



Advertisments