forked from seattlewill/multi-java
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUDPSender.java
More file actions
23 lines (17 loc) · 634 Bytes
/
UDPSender.java
File metadata and controls
23 lines (17 loc) · 634 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package network;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;
public class UDPSender {
public static void main(String[] args) throws Exception {
DatagramSocket socket = new DatagramSocket();
String str = "i am a android programmer!";
byte[] data = str.getBytes();
InetAddress ip = InetAddress.getByName("127.0.0.1");
DatagramPacket packet = new DatagramPacket(data, data.length, ip, 7100);
socket.send(packet);
System.out.println("클라이언트 포트>> " + socket.getLocalPort());
socket.close();
}
}