Computer Networking Laboratory
Computer Networking Laboratory
PROGRAM :-
import java.util.Scanner;
public class Echo {
public static void main(String[] args) {
String inData;
Scanner scan = new Scanner(System.in);
System.out.println("Enter the data:");
inData = scan.nextLine();
RESULT :-
Thus the Program has been successfully done and the Output is verified.
OUTPUT :-
PROGRAM :-
SERVER SIDE :-
import java.net.*;
import java.io.*;
public class Server {
public static void main(String[] args) {
try {
ServerSocket ss = new ServerSocket(1999);
Socket s = ss.accept( );
DataInputStream dis = new DataInputStream(s.getInputStream());
System.out.println(dis.readUTF());
} catch (IOException ie) {
ie.printStackTrace();
}
}
}
CLIENT SIDE:-
import java.net.*;
import java.io.*;
RESULT :-
Thus the Program has been successfully done and the Output is verified.
OUTPUT :-
PROGRAM :-
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
public class Ping {
public static void sendPingRequest(String ipAddress) throws
UnknownHostException, IOException {
InetAddress geek = InetAddress.getByName(ipAddress);
System.out.println("Sending Ping Request to " + ipAddress);
if (geek.isReachable(5000)) {
System.out.println("Host is reachable");
} else {
System.out.println("Sorry! We can't reach to this host");
}
}
public static void main(String[] args) throws
UnknownHostException, IOException {
String ipAddress = "172.20.105.46";
sendPingRequest(ipAddress);
}
}
RESULT :-
Thus the Program has been successfully done and the Output is verified.
OUTPUT :-
PROGRAM :-
SERVER SIDE :-
import java.io.*;
import java.net.*;
public class ServerRCE {
public static void main(String args[]) throws IOException {
try {
String str;
ServerSocket server = new ServerSocket(6555);
Socket s = server.accept();
BufferedReader br = new BufferedReader(new
InputStreamReader(s.getInputStream()));
str = br.readLine();
Runtime r = Runtime.getRuntime();
Process p = r.exec(str);
} catch (IOException e) {
System.out.println("Error");
}
}
}
CLIENT SIDE :-
import java.io.*;
import java.net.*;
public class ClientRCE {
public static void main(String args[]) throws IOException {
try {
String str;
Socket client = new Socket("localhost", 6555);
PrintStream ps = new PrintStream(client.getOutputStream());
BufferedReader br = new BufferedReader (new
InputStreamReader(System.in));
System.out.println("Enter The Command: ");
str = br.readLine();
ps.println(str);
ps.close();
br.close();
client.close();
} catch (IOException e) {
System.out.println("Error");}
}
}
RESULT :-
Thus the Program has been successfully done and the Output is verified.
OUTPUT :-
PROGRAM :-
import java.util.Scanner;
public class CRC {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n, m, i, j, k;
System.out.print("ENTER NUMBER OF DATA BITS:\n");
n = sc.nextInt();
System.out.print("ENTER NUMBER OF GENERATOR BITS:\n");
m = sc.nextInt();
RESULT :-
Thus the Program has been successfully done and the Output is verified.
OUTPUT :-
PROGRAM :-
return maxSum;
}
RESULT :-
Thus the Program has been successfully done and the Output is verified.
OUTPUT :-
PROGRAM :-
import java.util.Scanner;
public class TalkCommand {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Welcome to Talk Command!");
System.out.println("Type 'exit' to quit.");
while (true) {
System.out.print("You: ");
String input = scanner.nextLine();
if (input.equalsIgnoreCase("exit")) {
System.out.println("Exiting Talk Command. Goodbye!");
break;
}
System.out.println("Talk Command: Hello, you said: " + input);
}
scanner.close();
}
}
RESULT :-
Thus the Program has been successfully done and the Output is verified.
OUTPUT :-
PROGRAM :-
CLIENT SIDE :-
import java.net.*;
import java.io.*;
public class Client1 {
public static void main (String []args) {
try {
Socket s = new Socket("localhost", 1999);
DataOutputStream dos = new DataOutputStream(s.getOutputStream());
DataInputStream dis = new DataInputStream(s.getInputStream());
(System.in));
BufferedReader br = new BufferedReader(new InputStreamReader
while(!br.readLine().equals("quit")) {
dos.writeUTF(br.readLine());
System.out.println("He says: " + dis.readUTF());
dos.flush();
}
s.close();
} catch (IOException ie) {
ie.printStackTrace();
}
}
}
SERVER SIDE :-
import java.net.*;
import java.io.*;
public class Server1 {
public static void main (String []args) {
try {
ServerSocket ss = new ServerSocket (1999);
Sockets ss.accept();
DataOutputStream dos = new DataOutputStream(s.getOutputStream());
DataInputStream dis = new DataInputStream(s.getInputStream());
(System.in));
BufferedReader br = new BufferedReader(new InputStreamReader
while(!br.readLine().equals("quit")) {
System.out.println("She says: " + dis.readUTF());
dos.writeUTF(br.readLine());
}
ss.close();
} catch (Exception ie) {
ie.printStackTrace();
}}
}
RESULT :-
Thus the Program has been successfully done and the Output is verified.