我想编写一个Java代码,其中客户端使用UDP广播发送服务类型
public void run()
{
try
{
host = InetAddress.getByName(hostname);
socket = new DatagramSocket (null);
packet=new DatagramPacket (new byte[100], 0,host, port);
socket.send (packet);
packet.setLength(100);
socket.receive (packet);
socket.close ();
byte[] data = packet.getData ();
String time=new String(data); // convert byte array data into string
System.out.println(time);
}
catch(Exception e)
{
e.printStackTrace();
}`
}
}