0% found this document useful (0 votes)
70 views

Implementation of File System Calls

The document discusses implementation of remote procedure calls (RPC) between a server and client program in Java. The server program listens on port 3000 for connections from clients. The client program connects to the server and sends an operation (add, sub, mul, div) along with two integer parameters. The server performs the requested operation and sends the result back to the client. This allows for functions to be called remotely between programs communicating over a network.

Uploaded by

nisha kareem
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
70 views

Implementation of File System Calls

The document discusses implementation of remote procedure calls (RPC) between a server and client program in Java. The server program listens on port 3000 for connections from clients. The client program connects to the server and sends an operation (add, sub, mul, div) along with two integer parameters. The server performs the requested operation and sends the result back to the client. This allows for functions to be called remotely between programs communicating over a network.

Uploaded by

nisha kareem
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 17

Implementation Of File System Calls

#include<fcntl.h>
#include<stdio.h>
#include<conio.h>
void main()
{
int n, fd;
char buff[50];
clrscr();
printf("Enter text to write in the file:");
n=read(0, buff, 50);
fd=open("file", O_CREAT | O_RDWR, 0777);
write(fd, buff, n);
write(1, buff, n);
close(fd);
getch();
}

OUTPUT:

Enter text to write in the file: Department of Computer Science


Department of Computer Science
Implementation IPC Techinques(Pipe)

import java.io.*;
public class pipe
{
public static void main(String[]args) throws IOException
{
PipedInputStream input=new PipedInputStream();
PipedOutputStream output=new PipedOutputStream();
try
{
input.connect(output);
output.write(71);
System.out.println("using read();"+(char)input.read());
output.write(69);
System.out.println("using read();"+(char)input.read());
output.write(75);
System.out.println("using read();"+(char)input.read());
}
catch(IOException except)
{
except.printStackTrace();
}
}
}

Output:
system03@System03-PC:~/Desktop$ javac pipe.java
system03@System03-PC:~/Desktop$ java pipe
using read();G
using read();E
using read();K
Implementation Of IPC Techniques(Message Queue)

import java.util.LinkedList;
import java.util.Queue;
public class queue{

public static void main(String args[]) {

Queue<String> months = new LinkedList<String>();

System.out.println("Queue : " + months);


months.add("JAN");
months.add("FEB");
months.add("MAR");
months.add("APR");
months.add("MAY");
months.add("JUN");
months.add("JUL");
months.add("AUG");
months.add("SEP");
months.add("OCT");
months.add("NOV");
months.add("DEC");
System.out.println("Queue after initialization : " + months);
boolean hasMay = months.contains("MAY");
System.out.println("Does Queue has MAY in it? " + hasMay);
String head = months.peek();
System.out.println("Head of the Queue contains : " + head);
String oldHead = months.poll();
String newHead = months.peek();
System.out.println("old head : " + oldHead);
System.out.println("new head : " + newHead);
boolean hasJan = months.contains("JAN");
System.out.println("Does Queue has JAN in it? " + hasJan);
months.remove();
System.out.println("now head of Queue is: " + months.peek());
boolean hasFeb= months.contains("FEB");
System.out.println("Does Queue has FEB in it? " + hasFeb);

}
Output:

system03@System03-PC:~/Desktop$ javac queue.java


system03@System03-PC:~/Desktop$ java queue
Queue : []
Queue after initialization : [JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV,
DEC]
Does Queue has MAY in it? true
Head of the Queue contains : JAN
old head : JAN
new head : FEB
Does Queue has JAN in it? false
now head of Queue is: MAR
Does Queue has FEB in it? false
Socket Programming(TCP Sockets)

Server program:

import java.net.*;
import java.io.*;
import java.util.*;
class tcpser
{
public static void main(String arg[])
{
ServerSocket ss = null;
Socket cs;
PrintStream ps;
BufferedReader dis;
String inet;
try
{
ss = new ServerSocket(4444);
System.out.println("Press Ctrl+C to quit");
while(true)
{
cs = ss.accept();
ps = new PrintStream(cs.getOutputStream());
Date d = new Date();
ps.println(d);
dis = new BufferedReader(new
InputStreamReader(cs.getInputStream()));
inet = dis.readLine();
System.out.println("Client System/IP address is :"+ inet);
ps.close();dis.close();
}
}
catch(IOException e)
{
System.out.println("The exception is :" + e);
}
}
}

Client program

import java.net.*;
import java.io.*;
class tcpcli
{
public static void main (String args[])
{
Socket soc;
BufferedReader dis;
String sdate;
PrintStream ps;
try
{
InetAddress ia = InetAddress.getLocalHost();
if (args.length == 0)soc = new Socket(InetAddress.getLocalHost(),4444);
else
soc = new Socket(InetAddress.getByName(args[0]),4444);
dis = new BufferedReader(new
InputStreamReader(soc.getInputStream()));
sdate=dis.readLine();
System.out.println("The date/time on server is : " +sdate);
ps = new PrintStream(soc.getOutputStream());
ps.println(ia);
ps.close();
}
catch(IOException e)
{
System.out.println("THE EXCEPTION is :" + e);
}
}
}

OUTPUT:
server side:
system03@System03-PC:~/Desktop$ javac tcpser.java
system03@System03-PC:~/Desktop$ java tcpser
Press Ctrl+C to quit
Client System/IP address is :System03-PC/127.0.1.1

Client side:
system03@System03-PC:~/Desktop$ javac tcpcli.java
system03@System03-PC:~/Desktop$ java tcpcli
The date/time on server is : Mon Mar 09 13:09:24 IST 2020
Socket Programming( UDP Sockets)

Server Program:

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;

public class udpser


{
public static void main(String[] args) throws IOException
{

DatagramSocket ds = new DatagramSocket(1234);


byte[] receive = new byte[65535];

DatagramPacket DpReceive = null;


while (true)
{

DpReceive = new DatagramPacket(receive, receive.length);

ds.receive(DpReceive);

System.out.println("Client:-" + data(receive));

if (data(receive).toString().equals("bye"))
{
System.out.println("Client sent bye.....EXITING");
break;
}

receive = new byte[65535];


}
}

public static StringBuilder data(byte[] a)


{
if (a == null)
return null;
StringBuilder ret = new StringBuilder();
int i = 0;
while (a[i] != 0)
{
ret.append((char) a[i]);
i++;
}
return ret;
}
}

Client program:

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.util.Scanner;

public class udpcli


{
public static void main(String args[]) throws IOException
{
Scanner sc = new Scanner(System.in);

DatagramSocket ds = new DatagramSocket();

InetAddress ip = InetAddress.getLocalHost();
byte buf[] = null;
System.out.println("Type any Text:");

while (true)
{
String inp = sc.nextLine();

buf = inp.getBytes();

DatagramPacket DpSend =
new DatagramPacket(buf, buf.length, ip, 1234);

ds.send(DpSend);

if (inp.equals("bye"))
break;
}
}
}

OUTPUT:

Client:
system03@System03-PC:~/Desktop$ javac udpcli.java
system03@System03-PC:~/Desktop$ java udpcli
Type any Text:
HELLO
I AM CLIENT
HI
bye

Server:
system03@System03-PC:~/Desktop$ javac udpser.java
system03@System03-PC:~/Desktop$ java udpser
Client:-HELLO
Client:-I AM CLIENT
Client:-HI
Client:-bye
Client sent bye.....EXITING

Simulation Of Silding Window Protocol


Design:

Output:

Simulation of Routing Protocols


set ns [new Simulator]
set nf [open out.nam w]
$ns namtrace-all $nf
set tr [open out.tr w]
$ns trace-all $tr
proc finish {} {
global nf ns tr
$ns flush-trace
close $tr
exec nam out.nam &
exit 0
}
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
$ns duplex-link $n0 $n1 10Mb 10ms DropTail
$ns duplex-link $n1 $n3 10Mb 10ms DropTail
$ns duplex-link $n2 $n1 10Mb 10ms DropTail
$ns duplex-link-op $n0 $n1 orient right-down
$ns duplex-link-op $n1 $n3 orient right
$ns duplex-link-op $n2 $n1 orient right-up
set tcp [new Agent/TCP]
$ns attach-agent $n0 $tcp
set ftp [new Application/FTP]
$ftp attach-agent $tcp
set sink [new Agent/TCPSink]
$ns attach-agent $n3 $sink
set udp [new Agent/UDP]
$ns attach-agent $n2 $udp
set cbr [new Application/Traffic/CBR]
$cbr attach-agent $udp
set null [new Agent/Null]
$ns attach-agent $n3 $null
$ns connect $tcp $sink
$ns connect $udp $null
$ns rtmodel-at 1.0 down $n1 $n3
$ns rtmodel-at 2.0 up $n1 $n3
$ns rtproto LS

$ns at 0.0 "$ftp start"


$ns at 0.0 "$cbr start"
$ns at 5.0 "finish"
$ns run

OUTPUT:
RPC
Server:
import java.io.*;
import java.net.*;
class ser
{
public static void main(String[] args) throws Exception
{
ServerSocket sersock = new ServerSocket(3000);
System.out.println("Server ready");
Socket sock = sersock.accept( );
BufferedReader keyRead = new BufferedReader(new InputStreamReader(System.in));
OutputStream ostream = sock.getOutputStream();
PrintWriter pwrite = new PrintWriter(ostream, true);
InputStream istream = sock.getInputStream();
BufferedReader receiveRead = new BufferedReader(new InputStreamReader(istream));
String receiveMessage, sendMessage,fun;
int a,b,c;
while(true)
{
fun = receiveRead.readLine();
if(fun != null)
System.out.println("Operation : "+fun);
a = Integer.parseInt(receiveRead.readLine());
System.out.println("Parameter 1 : "+a);
b = Integer.parseInt(receiveRead.readLine());
if(fun.compareTo("add")==0)
{
c=a+b;
System.out.println("Addition = "+c);
pwrite.println("Addition = "+c);
}
if(fun.compareTo("sub")==0)
{
c=a-b;
System.out.println("Substraction = "+c);
pwrite.println("Substraction = "+c);
}
if(fun.compareTo("mul")==0)
{
c=a*b;
System.out.println("Multiplication = "+c);
pwrite.println("Multiplication = "+c);
}
if(fun.compareTo("div")==0)
{
c=a/b;
System.out.println("Division = "+c);
pwrite.println("Division = "+c);
}
System.out.flush();
}
}
}

Client:
import java.io.*;
import java.net.*;
class cli
{
public static void main(String[] args) throws Exception
{
Socket sock = new Socket("127.0.0.1", 3000);
BufferedReader keyRead = new BufferedReader(new InputStreamReader(System.in));
OutputStream ostream = sock.getOutputStream();
PrintWriter pwrite = new PrintWriter(ostream, true);
InputStream istream = sock.getInputStream();
BufferedReader receiveRead = new BufferedReader(new InputStreamReader(istream));
System.out.println("Client ready, type and press Enter key");
String receiveMessage, sendMessage,temp;
while(true)
{
System.out.println("\nEnter operation to perform(add,sub,mul,div)....");
temp = keyRead.readLine();
sendMessage=temp.toLowerCase();
pwrite.println(sendMessage);
System.out.println("Enter first parameter :");
sendMessage = keyRead.readLine();
pwrite.println(sendMessage);
System.out.println("Enter second parameter : ");
sendMessage = keyRead.readLine();
pwrite.println(sendMessage);
System.out.flush();
if((receiveMessage = receiveRead.readLine()) != null)
System.out.println(receiveMessage);
}
}
}

Output:
Server:
system03@System03-PC:~/Desktop$ javac ser.java
system03@System03-PC:~/Desktop$ java ser
Server ready
Operation : add
Parameter 1 : 5
Addition = 13

Client:
system03@System03-PC:~/Desktop$ javac cli.java
system03@System03-PC:~/Desktop$ java cli
Client ready, type and press Enter key

Enter operation to perform(add,sub,mul,div)....


add
Enter first parameter :
5
Enter second parameter :
8
Addition = 13

Enter operation to perform(add,sub,mul,div)....

Development Of Applications Such as DNS


import java.net.*;
import java.io.*;
import java.util.*;

public class dns


{
public static void main(String[] args)
{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

try
{
System.out.println("\n Enter Host Name ");
String hname=in.readLine();
InetAddress address;
address = InetAddress.getByName(hname);
System.out.println("Host Name: " + address.getHostName());
System.out.println("IP: " + address.getHostAddress());
}
catch(IOException ioe)
{
ioe.printStackTrace();
}
}

Output:
system03@System03-PC:~/Desktop$ javac dns.java
system03@System03-PC:~/Desktop$ java dns

Enter Host Name


www.youtube.com
Host Name: www.youtube.com
IP: 172.217.25.14

Development Of Applications such as HTTP


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class http {

public static void main(String args[]) throws IOException {

URL url = new URL("https://api.github.com/users/google");


HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("GET");
BufferedReader in = new BufferedReader(new InputStreamReader(
con.getInputStream()));
String inputLine;
while ((inputLine=in.readLine())!= null) {
System.out.println(inputLine);

in.close();
}
}

Output:
system03@System03-PC:~/Desktop$ javac http.java
system03@System03-PC:~/Desktop$ java http
{"login":"google","id":1342004,"node_id":"MDEyOk9yZ2FuaXphdGlvbjEzNDIwMDQ=","ava
tar_url":"https://avatars1.githubusercontent.com/u/1342004?
v=4","gravatar_id":"","url":"https://api.github.com/users/google","html_url":"https://github.com/
google","followers_url":"https://api.github.com/users/google/followers","following_url":"https://
api.github.com/users/google/following{/other_user}","gists_url":"https://api.github.com/users/go
ogle/gists{/gist_id}","starred_url":"https://api.github.com/users/google/starred{/owner}
{/repo}","subscriptions_url":"https://api.github.com/users/google/subscriptions","organizations_
url":"https://api.github.com/users/google/orgs","repos_url":"https://api.github.com/users/google/r
epos","events_url":"https://api.github.com/users/google/events{/privacy}","received_events_url"
:"https://api.github.com/users/google/received_events","type":"Organization","site_admin":false,
"name":"Google","company":null,"blog":"https://opensource.google/","location":null,"email":"o
[email protected]","hireable":null,"bio":"Google ❤️Open
Source","public_repos":1689,"public_gists":0,"followers":0,"following":0,"created_at":"2012-
01-18T01:30:18Z","updated_at":"2019-12-19T21:09:14Z"}

You might also like