创建UDP服务器
import java.io.*; import java.net.*; class UDPServer { /** from n o w j a v a . c o m**/ public static void main(String args[]) throws IOException { DatagramSocket serverSocket = new DatagramSocket(9876); byte[] receiveData = new byte[1024]; byte[] sendData = new byte[1024]; while(true) { DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length); serverSocket.receive(receivePacket); String sentence = new String(receivePacket.getData()); System.out.println("RECEIVED: " + sentence); InetAddress IPAddress = receivePacket.getAddress(); /**来自 时 代 Java 公 众 号 - nowjava.com**/ int port = receivePacket.getPort(); String capitalizedSentence = sentence.toUpperCase();