0% found this document useful (0 votes)
17 views17 pages

File System and IPC Techniques Implementation

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)
17 views17 pages

File System and IPC Techniques Implementation

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

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 13:09:24 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-18T01:30:18Z","updated_at":"2019-12-19T21:09:14Z"}

Common questions

Powered by AI

The TCP socket programming example demonstrates communication by creating a `ServerSocket` on the server side, which listens for connections on a specific port (`4444`). When a client connects, it accepts the connection and uses a `PrintStream` to send the server's date and time. The client establishes a socket connection to the server, reads the data using a `BufferedReader`, and sends its IP address back to the server. This model illustrates a typical client-server architecture where multiple clients can connect to a server that continuously listens for incoming connections .

TCP socket programming establishes a reliable connection-oriented communication channel where data is transmitted in a stream, ensuring that it arrives intact and in order. It is suited for applications requiring data integrity and sequential delivery. In contrast, UDP socket programming is connectionless, sending data in discrete packets without guaranteeing delivery, making it suitable for applications where speed is critical, such as streaming. TCP requires a handshake before communication, adding overhead, while UDP enables faster transmission without setup delays, but at the cost of reduced reliability .

The sliding window protocol simulation, demonstrated using a network simulator, helps in understanding flow control mechanisms in reliable data transmission. This protocol controls the amount of data that can be sent before needing an acknowledgment, crucial for efficient use of network resources and preventing congestion. Networking applications utilize sliding window techniques to maintain data integrity and optimize throughput over varying network conditions. It is significant in developing robust communication protocols, such as TCP, that facilitate efficient data transfer across networks .

The Java code demonstrates basic RPC functionality by setting up a server that listens for operations sent from clients. The server responds to different arithmetic operations (add, sub, mul, div) requested by reading operation names and parameters from the client through `BufferedReader`, performs the operations, and sends back results via `PrintWriter`. This mimics RPC by allowing the client to request computations to be performed remotely by the server, highlighting the interaction process over a TCP connection .

The HTTP implementation in Java demonstrates creating an HTTP GET request to fetch and display data from a URL (`https://api.github.com/users/google`). It facilitates network interactions such as consuming web APIs, fetching data remotely, and interacting with web resources. However, its limitations include no built-in support for handling retries, timeouts, or concurrent requests, and it requires manual parsing of response data, which can be cumbersome for complex responses. Additionally, security aspects like SSL/TLS are not addressed directly in this basic implementation .

The C program uses the `open()` system call to create or open a file with read and write permissions. Then, it uses the `read()` function to capture input from the standard input (descriptor 0) into a buffer. The `write()` function is utilized twice: first, to write the buffer contents to the open file descriptor (`fd`), and second, to display the same contents on the standard output (descriptor 1). Finally, `close()` is called to close the file descriptor, ensuring resource management is properly handled .

The UDP socket programming example maintains communication using `DatagramSocket` and `DatagramPacket` objects. The server continuously listens for datagram packets on a specified port (`1234`) and processes incoming data until it receives a termination signal ('bye'). The client sends data by converting messages into byte arrays and transmitting them via `send()` method. The use of DatagramPacket allows for connectionless communication, where the server does not establish a continuous connection with the client, ensuring a lightweight data exchange mechanism .

The DNS lookup implementation in Java utilizes `InetAddress` to obtain the IP address from a hostname entered by the user. This example demonstrates a basic DNS resolution process in which the Java program abstracts lower-level DNS operations, enabling applications to resolve IP addresses for hostnames. Potential use cases include network diagnostics, IP address validation, or applications requiring hostname-to-IP resolution as part of setup routines or network communications .

The Java queue implementation uses a `LinkedList` as the underlying data structure for queuing messages. It supports operations such as `add()` to enqueue elements, `peek()` to inspect the element at the head without removal, `poll()` to dequeue and return the head element, and `contains()` to check for the presence of specific elements. These operations demonstrate the standard characteristics of a FIFO (First-In-First-Out) queue .

The process of IPC using pipes in Java involves creating a `PipedInputStream` and a `PipedOutputStream`. The streams are connected with `input.connect(output)`. Data is written to the output stream, and the same data is read from the input stream using `input.read()`. This demonstrates byte-level communication between the output and input streams, simulating communication between different processes by passing data through the pipe .

You might also like