java udp sockect编程

i use Java udp socket write a program today.

classes used:
DatagramScocket(int port);
DatagramPacket(byte[] buf, int length, InetAddress address,int port); //for send
DatagramPacket(byte[] buf, int length); //for receive

implements:
first, construct a DatagramSocket object with a specified port.
then construct a DatagramPacket with a buffer, length, InetAddress and port to send you message,
the message is stored in the buffer which is a byte array.

also you can construct a DatagramPacket with a buffer and length to recieve message from the port blinded with you socket.


note:
if you send message to a server that not recieve you message , the message is lost. this future is differnet to tcp connetion.
so to make udp program , you must deal with package lost!!!

udp为不可靠传送,必须处理包丢失的问题

你可能感兴趣的:(java,编程,socket)