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

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

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

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

    Re: sending objects over sockets

    Knute Johnson, Jun 27, 2003, in forum: Java
    Replies:
    5
    Views:
    3,406
    Steve Horsley
    Jun 28, 2003
  2. Steve Horsley
    Replies:
    4
    Views:
    1,781
    Jon A. Cruz
    Aug 29, 2003
  3. Tim Black
    Replies:
    1
    Views:
    2,729
    Alan Kennedy
    Aug 3, 2004
  4. Replies:
    9
    Views:
    1,261
    Simon Forman
    Jul 4, 2006
  5. Tomek Gruca
    Replies:
    15
    Views:
    5,741
  6. 7stud
    Replies:
    11
    Views:
    1,054
    Dennis Lee Bieber
    Mar 20, 2007
  7. Ryniek90
    Replies:
    0
    Views:
    346
    Ryniek90
    Apr 17, 2009
  8. Navkirat Singh

    Sending HTTP headers via plain sockets

    Navkirat Singh, Jul 23, 2010, in forum: Python
    Replies:
    0
    Views:
    332
    Navkirat Singh
    Jul 23, 2010
Loading...