Professional Documents
Culture Documents
AIM : Write a program to find IP address of a given host name and to find host name of given
IP address .
import java.util.*;
import java.net.*;
public class JavaApplication38 {
public static void main(String[] args) throws UnknownHostException{
System.out.println("enter the IP address");
Scanner sc= new Scanner(System.in);
String str= sc.next();
InetAddress host =InetAddress.getByName(str);
System.out.println(host.getHostName());
String str1= sc.next();
InetAddress host1= InetAddress.getByName(str1);
System.out.println(host1.getHostAddress());
}
}
OUTPUT
Signature
Acropolis Institute of Technology & Research, Indore
Department of Computer Science & Engineering
import java.io.*;
import java.net.*;
public class Server {
public static void main(String[] args) {
try {
ServerSocket server=new ServerSocket(3000);
Socket s=server.accept();
system.out.println("Connected");
} catch (IOException e) {
}
}
}
Client-
import java.io.IOException;
import java.net.*;
public class Client {
public static void main(String[] args) {
try {
Socket s=new Socket("192.168.0.4",3000);
System.out.println("Connected");
} catch (IOException e) {
}
}
}
Signature
Acropolis Institute of Technology & Research, Indore
Department of Computer Science & Engineering
OUTPUT
Signature
Acropolis Institute of Technology & Research, Indore
Department of Computer Science & Engineering
Server-.
import java.io.*;
import java.net.*;
public class ServerMsg {
public static void main(String[] args) {
try {
ServerSocket server=new ServerSocket(4000);
Socket s=server.accept();
system.out.println("Connected");
DataOutputStream dos=new
DataOutputStream(s.getOutputStream());
dos.writeUTF("Welcome to karachi");
} catch (IOException e) {
}
}
}
Client-.
import java.io.*;
import java.net.*;
public class ClientMsg {
public static void main(String[] args) {
try {
Socket s=new Socket("192.168.0.4",4000);
system.out.println("Connected");
DataInputStream dis=new DataInputStream(s.getInputStream());
String msg=dis.readUTF();
system.out.println(msg);
} catch (IOException e) {
}
}
}
Signature
Acropolis Institute of Technology & Research, Indore
Department of Computer Science & Engineering
OUTPUT
Signature
Acropolis Institute of Technology & Research, Indore
Department of Computer Science & Engineering
Program 12
AIM : Write a program to create a program to send message from Client to server.
Server-
import java.io.*;
import java.net.*;
Client-
import java.io.*;
import java.net.*;
Signature
Acropolis Institute of Technology & Research, Indore
Department of Computer Science & Engineering
OUTPUT
Signature