You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
19 lines
520 B
19 lines
520 B
package 发送接收数据;
|
|
|
|
import java.io.IOException;
|
|
import java.net.*;
|
|
|
|
public class sendMessage {
|
|
public static void main(String[] args) throws IOException {
|
|
DatagramSocket ds=new DatagramSocket();
|
|
String str="你好啊";
|
|
byte[] bytes=str.getBytes();
|
|
InetAddress address=InetAddress.getByName("127.0.0.1");
|
|
int port=10086;
|
|
DatagramPacket dp=new DatagramPacket(bytes,bytes.length,address,port);
|
|
ds.send(dp);
|
|
ds.close();
|
|
|
|
}
|
|
}
|