sending objects over sockets?

Discussion in 'Java' started by Don, Oct 25, 2003.

  1. Don

    Don Guest

    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
    Don, Oct 25, 2003
    #1
    1. Advertising

  2. [ 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
    Gordon Beaton, Oct 25, 2003
    #2
    1. Advertising

  3. Don

    Roedy Green Guest

    On 25 Oct 2003 13:03:06 -0700, (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.
    Roedy Green, Oct 25, 2003
    #3
  4. Don

    Joe Guest

    In article <>,
    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
    Joe, Oct 26, 2003
    #4
  5. Don

    Roedy Green Guest

    On Sat, 25 Oct 2003 16:21:36 -0700, Joe <> 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.
    Roedy Green, Oct 26, 2003
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steve Horsley

    Re: sending objects over sockets

    Steve Horsley, Jun 27, 2003, in forum: Java
    Replies:
    0
    Views:
    1,141
    Steve Horsley
    Jun 27, 2003
  2. Steve Horsley

    Re: sending objects over sockets

    Steve Horsley, Jun 27, 2003, in forum: Java
    Replies:
    0
    Views:
    1,406
    Steve Horsley
    Jun 27, 2003
  3. Knute Johnson

    Re: sending objects over sockets

    Knute Johnson, Jun 27, 2003, in forum: Java
    Replies:
    5
    Views:
    3,194
    Steve Horsley
    Jun 28, 2003
  4. Gilles Dubochet

    Re: Sending bytes and string over sockets

    Gilles Dubochet, Aug 26, 2003, in forum: Java
    Replies:
    0
    Views:
    448
    Gilles Dubochet
    Aug 26, 2003
  5. Steve Horsley
    Replies:
    4
    Views:
    1,418
    Jon A. Cruz
    Aug 29, 2003
Loading...

Share This Page