Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
JASWANTH
REG.NO : 17MIS0379
SLOT : L59+L60
To study about InetAddress and NetworkInterface classes and
its methods
(i)Program:
GetByName.java
import java.net.*;
public class GetByName {
public static void main (String[] args) {
try {
InetAddress address = InetAddress.getByName("www.vit.ac.in");
System.out.println(address);
}
catch (UnknownHostException ex) {
System.out.println("Could not find www.vit.ac.in");
}
}
}
Output:
Ip address:10.10.1.75
(ii)Program:
Myaddress.java
import java.net.*;
try {
System.out.println(address);
(iii)Program:
InterfaceLister.java
import java.net.*;
import java.util.*;
while (interfaces.hasMoreElements()) {
System.out.println(ni);
}
Output:
Objective:
To implement a simple message transfer from client to server process using TCP
sockets.
Questions:
1. To develop a client side program to send the message to the server.
2. To develop a server side program to receive the message from the client and
display it.
1.Program:
Server .java
import java.net.*;
import java.io.*;
try {
System.out.println();
InputStreamReader(System.in));
while(true) {
line = in.readUTF();
line=keyboard.readLine();
out.writeUTF(line);
System.out.println();
ss.close();
}
Output:
2.Program:
Client.java
import java.net.*;
import java.io.*;
try {
InputStreamReader(System.in));
System.out.println();
while(true) {
line = keyboard.readLine();
out.writeUTF(line);
out.flush();
line = in.readUTF();
System.out.println();
Output:
Objective:
To implement a simple message transfer from client to server process using UDP
sockets.
Questions:
2. To develop a server side program to receive the message from the client and
display it.
1.Program:
Server .java
import java.net.*;
import java.io.*;
try {
ds.receive(incoming);
message:");
System.out.println(s);
}
catch (IOException e) {
System.err.println(e);
Output:
2.Program:
Client.java
import java.net.*;
import java.io.*;
try {
int p = 19;
byte[] b = s.getBytes();
sender.send(dp);
Output: