forked from deepdalsania/tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUDP_Client.java
More file actions
35 lines (29 loc) · 979 Bytes
/
UDP_Client.java
File metadata and controls
35 lines (29 loc) · 979 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package netpck;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
public class UDP_Client {
/**
* @param args
* @throws IOException
* @throws NumberFormatException
*/
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
DatagramSocket ds = new DatagramSocket();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
/*System.out.println("Enter size of an ARRAY : ");
int n = Integer.parseInt(br.readLine());
byte[] b = new byte[n];*/
System.out.println("<< Client to Server >>"+"\n Enter your name : ");
String s = br.readLine();
InetAddress ip = InetAddress.getLocalHost();
DatagramPacket dp = new DatagramPacket(s.getBytes() , s.length() , ip , 1301 );
ds.send(dp);
System.out.println("Packet Send Succesfully...");
ds.close();
}
}