UDP protocol & Object

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • SpitFire

    UDP protocol & Object

    I need little help with Java and UDP protocol.

    Can someone give me an example of how can I send a object by UDP protocol.
    Only usefull method is

    DatagramPacket( byte[] buf, int length, InetAddress address, int port)

    but how to send object ( Data ) through UDP.


    Thanks.



  • Jared Dykstra

    #2
    Re: UDP protocol & Object

    "SpitFire" <max00@net.hrRE MOVENOSPAM> wrote in message news:<bsni83$jc 4$1@bagan.srce. hr>...[color=blue]
    > I need little help with Java and UDP protocol.
    >
    > Can someone give me an example of how can I send a object by UDP protocol.
    > Only usefull method is
    >
    > DatagramPacket( byte[] buf, int length, InetAddress address, int port)
    >
    > but how to send object ( Data ) through UDP.
    >
    >
    > Thanks.[/color]

    Serialize the object. That's what object serialization was designed for.


    ---
    Jared Dykstra

    Comment

    • Karl von Laudermann

      #3
      Re: UDP protocol &amp; Object

      "SpitFire" <max00@net.hrRE MOVENOSPAM> wrote in message news:<bsni83$jc 4$1@bagan.srce. hr>...[color=blue]
      > I need little help with Java and UDP protocol.
      >
      > Can someone give me an example of how can I send a object by UDP protocol.
      > Only usefull method is
      >
      > DatagramPacket( byte[] buf, int length, InetAddress address, int port)
      >
      > but how to send object ( Data ) through UDP.
      >
      >
      > Thanks.[/color]

      Easy. First, create a DatagramSocket:

      DatagramSocket udpSocket = new DatagramSocket( );

      Then, use the send() method to send a DatagramPacket on this socket:

      udpSocket.send( new DatagramPacket( buf, buf.length, address, port));

      You probably want to wait for a response if the recipient is expected to respond:

      byte[] retBuf = new byte[1024];
      DatagramPacket response = new DatagramPacket( retBuf, retBuf.length);
      udpSocket.recei ve(response);

      Check out the Java tutorial for more details:
      This networking Java tutorial describes networking capabilities of the Java platform, working with URLs, sockets, datagrams, and cookies

      Comment

      • SpitFire

        #4
        Re: UDP protocol &amp; Object


        "Jared Dykstra" <dyksjare@hotma il.com> wrote:[color=blue]
        > Serialize the object. That's what object serialization was designed for.
        > http://www.acm.org/crossroads/xrds4-2/serial.html
        >[/color]

        It's working :-)
        Thanks


        Comment

        Working...