package com.itcast_01;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;
import java.net.UnknownHostException;
public class Demo1_Send {
public static void main(String[] args) throws IOException {
String str = "你好啊";
DatagramSocket socket = new DatagramSocket();
DatagramPacket packet = new DatagramPacket(str.getBytes(),//本机ip,端口2425
str.getBytes().length, InetAddress.getByName("192.168.156.3"), 2425);// 集装箱,装好东西,装好要发送的东西和发送给别人的地址和别人的端口号
socket.send(packet);// 发货,将数据发出去
socket.close();
}
}
|
|