UDP将文章数据报文包发送到给定的主机。
//package com.nowjava; import java.io.IOException; import java.net.DatagramPacket;/**来自 时代Java公众号 - nowjava.com**/ import java.net.DatagramSocket; import java.net.InetAddress; public class Main { public static void main(String[] argv) throws Exception { String host = "nowjava.com"; int port = 2; String article = "nowjava.com"; send(host, port, article); }//from 时代Java - N o w J a v a . c o m /** * Send article data gram packet to given host. * * @param host * @param port * @param article * @throws IOException */ public static void send(String host, int port, String article) throws IOException { DatagramSocket socket = new DatagramSocket(); InetAddress addr = InetAddress.getByName(host);