Re: UDP protocol & Object
From: Karl von Laudermann (karl_at_ueidaq.com)
Date: 12/30/03
- Next message: Paul P: "Vector Question for Newbie"
- Previous message: Jared Dykstra: "Re: Anyone know about ActiveX in Java?"
- In reply to: SpitFire: "UDP protocol & Object"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 30 Dec 2003 08:10:58 -0800
"SpitFire" <max00@net.hrREMOVENOSPAM> wrote in message news:<bsni83$jc4$1@bagan.srce.hr>...
> 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.
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.receive(response);
Check out the Java tutorial for more details:
http://java.sun.com/docs/books/tutorial/networking/index.html
- Next message: Paul P: "Vector Question for Newbie"
- Previous message: Jared Dykstra: "Re: Anyone know about ActiveX in Java?"
- In reply to: SpitFire: "UDP protocol & Object"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|