集册 Java实例教程 发送数据报

发送数据报

欢马劈雪     最近更新时间:2020-01-02 10:19:05

471
发送数据报

import java.io.IOException;

import java.net.DatagramPacket;/** 来自 时代Java公众号 - nowjava.com**/

import java.net.DatagramSocket;

import java.net.InetAddress;

import java.net.SocketException;


public class Main {

  public static void send(InetAddress dst, int port, byte[] outbuf, int len) {

    try {

      DatagramPacket request = new DatagramPacket(outbuf, len, dst, port);

      DatagramSocket socket = new DatagramSocket();

      socket.send(request);

展开阅读全文