-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDNSClient.java
31 lines (31 loc) · 932 Bytes
/
DNSClient.java
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
import java.io.*;
import java.net.*;
public class DNSClient
{
public static DatagramSocket ds;
public static int clientport=859, serverport=860;
public static void main(String args[]) throws Exception
{
System.out.println("\n\n\tDNS Client using UDP\n");
byte buffer[]=new byte[5178];
ds=new DatagramSocket(serverport);
BufferedReader dis=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Server waiting\n");
InetAddress ia=InetAddress.getLocalHost();
while(true)
{
System.out.println("Client: ");
String str=dis.readLine();
if(str.equals("end"))
{
break;
}
buffer=str.getBytes();
ds.send(new DatagramPacket(buffer, str.length(), ia, clientport));
DatagramPacket p=new DatagramPacket(buffer, buffer.length);
ds.receive(p);
String psx=new String(p.getData(), 0, p.getLength());
System.out.println("Server: "+psx);
}
}
}