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 [Link].*;
public class pipe
{
public static void main(String[]args) throws IOException
{
PipedInputStream input=new PipedInputStream();
PipedOutputStream output=new PipedOutputStream();
try
{
[Link](output);
[Link](71);
[Link]("using read();"+(char)[Link]());
[Link](69);
[Link]("using read();"+(char)[Link]());
[Link](75);
[Link]("using read();"+(char)[Link]());
}
catch(IOException except)
{
[Link]();
}
}
}
Output:
system03@System03-PC:~/Desktop$ javac [Link]
system03@System03-PC:~/Desktop$ java pipe
using read();G
using read();E
using read();K
Implementation Of IPC Techniques(Message Queue)
import [Link];
import [Link];
public class queue{
public static void main(String args[]) {
Queue<String> months = new LinkedList<String>();
[Link]("Queue : " + months);
[Link]("JAN");
[Link]("FEB");
[Link]("MAR");
[Link]("APR");
[Link]("MAY");
[Link]("JUN");
[Link]("JUL");
[Link]("AUG");
[Link]("SEP");
[Link]("OCT");
[Link]("NOV");
[Link]("DEC");
[Link]("Queue after initialization : " + months);
boolean hasMay = [Link]("MAY");
[Link]("Does Queue has MAY in it? " + hasMay);
String head = [Link]();
[Link]("Head of the Queue contains : " + head);
String oldHead = [Link]();
String newHead = [Link]();
[Link]("old head : " + oldHead);
[Link]("new head : " + newHead);
boolean hasJan = [Link]("JAN");
[Link]("Does Queue has JAN in it? " + hasJan);
[Link]();
[Link]("now head of Queue is: " + [Link]());
boolean hasFeb= [Link]("FEB");
[Link]("Does Queue has FEB in it? " + hasFeb);
}
Output:
system03@System03-PC:~/Desktop$ javac [Link]
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 [Link].*;
import [Link].*;
import [Link].*;
class tcpser
{
public static void main(String arg[])
{
ServerSocket ss = null;
Socket cs;
PrintStream ps;
BufferedReader dis;
String inet;
try
{
ss = new ServerSocket(4444);
[Link]("Press Ctrl+C to quit");
while(true)
{
cs = [Link]();
ps = new PrintStream([Link]());
Date d = new Date();
[Link](d);
dis = new BufferedReader(new
InputStreamReader([Link]()));
inet = [Link]();
[Link]("Client System/IP address is :"+ inet);
[Link]();[Link]();
}
}
catch(IOException e)
{
[Link]("The exception is :" + e);
}
}
}
Client program
import [Link].*;
import [Link].*;
class tcpcli
{
public static void main (String args[])
{
Socket soc;
BufferedReader dis;
String sdate;
PrintStream ps;
try
{
InetAddress ia = [Link]();
if ([Link] == 0)soc = new Socket([Link](),4444);
else
soc = new Socket([Link](args[0]),4444);
dis = new BufferedReader(new
InputStreamReader([Link]()));
sdate=[Link]();
[Link]("The date/time on server is : " +sdate);
ps = new PrintStream([Link]());
[Link](ia);
[Link]();
}
catch(IOException e)
{
[Link]("THE EXCEPTION is :" + e);
}
}
}
OUTPUT:
server side:
system03@System03-PC:~/Desktop$ javac [Link]
system03@System03-PC:~/Desktop$ java tcpser
Press Ctrl+C to quit
Client System/IP address is :System03-PC/[Link]
Client side:
system03@System03-PC:~/Desktop$ javac [Link]
system03@System03-PC:~/Desktop$ java tcpcli
The date/time on server is : Mon Mar 09 [Link] IST 2020
Socket Programming( UDP Sockets)
Server Program:
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
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, [Link]);
[Link](DpReceive);
[Link]("Client:-" + data(receive));
if (data(receive).toString().equals("bye"))
{
[Link]("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)
{
[Link]((char) a[i]);
i++;
}
return ret;
}
}
Client program:
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class udpcli
{
public static void main(String args[]) throws IOException
{
Scanner sc = new Scanner([Link]);
DatagramSocket ds = new DatagramSocket();
InetAddress ip = [Link]();
byte buf[] = null;
[Link]("Type any Text:");
while (true)
{
String inp = [Link]();
buf = [Link]();
DatagramPacket DpSend =
new DatagramPacket(buf, [Link], ip, 1234);
[Link](DpSend);
if ([Link]("bye"))
break;
}
}
}
OUTPUT:
Client:
system03@System03-PC:~/Desktop$ javac [Link]
system03@System03-PC:~/Desktop$ java udpcli
Type any Text:
HELLO
I AM CLIENT
HI
bye
Server:
system03@System03-PC:~/Desktop$ javac [Link]
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 [Link] w]
$ns namtrace-all $nf
set tr [open [Link] w]
$ns trace-all $tr
proc finish {} {
global nf ns tr
$ns flush-trace
close $tr
exec nam [Link] &
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 [Link].*;
import [Link].*;
class ser
{
public static void main(String[] args) throws Exception
{
ServerSocket sersock = new ServerSocket(3000);
[Link]("Server ready");
Socket sock = [Link]( );
BufferedReader keyRead = new BufferedReader(new InputStreamReader([Link]));
OutputStream ostream = [Link]();
PrintWriter pwrite = new PrintWriter(ostream, true);
InputStream istream = [Link]();
BufferedReader receiveRead = new BufferedReader(new InputStreamReader(istream));
String receiveMessage, sendMessage,fun;
int a,b,c;
while(true)
{
fun = [Link]();
if(fun != null)
[Link]("Operation : "+fun);
a = [Link]([Link]());
[Link]("Parameter 1 : "+a);
b = [Link]([Link]());
if([Link]("add")==0)
{
c=a+b;
[Link]("Addition = "+c);
[Link]("Addition = "+c);
}
if([Link]("sub")==0)
{
c=a-b;
[Link]("Substraction = "+c);
[Link]("Substraction = "+c);
}
if([Link]("mul")==0)
{
c=a*b;
[Link]("Multiplication = "+c);
[Link]("Multiplication = "+c);
}
if([Link]("div")==0)
{
c=a/b;
[Link]("Division = "+c);
[Link]("Division = "+c);
}
[Link]();
}
}
}
Client:
import [Link].*;
import [Link].*;
class cli
{
public static void main(String[] args) throws Exception
{
Socket sock = new Socket("[Link]", 3000);
BufferedReader keyRead = new BufferedReader(new InputStreamReader([Link]));
OutputStream ostream = [Link]();
PrintWriter pwrite = new PrintWriter(ostream, true);
InputStream istream = [Link]();
BufferedReader receiveRead = new BufferedReader(new InputStreamReader(istream));
[Link]("Client ready, type and press Enter key");
String receiveMessage, sendMessage,temp;
while(true)
{
[Link]("\nEnter operation to perform(add,sub,mul,div)....");
temp = [Link]();
sendMessage=[Link]();
[Link](sendMessage);
[Link]("Enter first parameter :");
sendMessage = [Link]();
[Link](sendMessage);
[Link]("Enter second parameter : ");
sendMessage = [Link]();
[Link](sendMessage);
[Link]();
if((receiveMessage = [Link]()) != null)
[Link](receiveMessage);
}
}
}
Output:
Server:
system03@System03-PC:~/Desktop$ javac [Link]
system03@System03-PC:~/Desktop$ java ser
Server ready
Operation : add
Parameter 1 : 5
Addition = 13
Client:
system03@System03-PC:~/Desktop$ javac [Link]
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 [Link].*;
import [Link].*;
import [Link].*;
public class dns
{
public static void main(String[] args)
{
BufferedReader in = new BufferedReader(new InputStreamReader([Link]));
try
{
[Link]("\n Enter Host Name ");
String hname=[Link]();
InetAddress address;
address = [Link](hname);
[Link]("Host Name: " + [Link]());
[Link]("IP: " + [Link]());
}
catch(IOException ioe)
{
[Link]();
}
}
Output:
system03@System03-PC:~/Desktop$ javac [Link]
system03@System03-PC:~/Desktop$ java dns
Enter Host Name
[Link]
Host Name: [Link]
IP: [Link]
Development Of Applications such as HTTP
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class http {
public static void main(String args[]) throws IOException {
URL url = new URL("[Link]
HttpURLConnection con = (HttpURLConnection) [Link]();
[Link]("GET");
BufferedReader in = new BufferedReader(new InputStreamReader(
[Link]()));
String inputLine;
while ((inputLine=[Link]())!= null) {
[Link](inputLine);
[Link]();
}
}
Output:
system03@System03-PC:~/Desktop$ javac [Link]
system03@System03-PC:~/Desktop$ java http
{"login":"google","id":1342004,"node_id":"MDEyOk9yZ2FuaXphdGlvbjEzNDIwMDQ=","ava
tar_url":"[Link]
v=4","gravatar_id":"","url":"[Link]
google","followers_url":"[Link]
[Link]/users/google/following{/other_user}","gists_url":"[Link]
ogle/gists{/gist_id}","starred_url":"[Link]
{/repo}","subscriptions_url":"[Link]
url":"[Link]
epos","events_url":"[Link]
:"[Link]
"name":"Google","company":null,"blog":"[Link]
pensource@[Link]","hireable":null,"bio":"Google ❤️Open
Source","public_repos":1689,"public_gists":0,"followers":0,"following":0,"created_at":"2012-
01-18T[Link]Z","updated_at":"2019-12-19T[Link]Z"}