Monday, August 13, 2012

operating system program b.tech.


EXPERIMENT 1
AIM: Write a program for FCFS(first come first serve)

TABLE:


PROCESS

BURST TIME
WAITING TIME
TURN AROUND TIME
P1
24
0
24
P2
3
24
24
P3
3
27
30




GRANTT CHART:
P1
P2
P3
0                                                              24                                                           27                                           30






PROGRAM:
#include<iostream.h>
#include<conio.h>
class fcfs
{
  int b_time[10];
  int w_time[10];
  int n_jobs[10];
  float avg;
  public:
  fcfs()
  {
  n_jobs=0;
  avg=0;
  }
  void job_entry(int n)
  {
  n_jobs=n;
  cout<<"\n enter the burst time of each job:";
  cout<<"\n";
  for(int i=0;i<n_jobs;i++)
  {
  cout<<"\n job"<<i+1<<":";
  cin>>b_time[i];
  }
  }
  void wait_time(void)
  {
  for(int i=0;i<n_jobs;i++)
  {
  id_time[i]=0;
  for(int j=0;j<1;j++)
  {
  w_time[i]=w_time[i]+t_time[j];
  }
  avg=avg+w_time[i];
  }
  avg=avg/n_jobs;
  cout<<"\n\t grant chart";
  for(i=0;i<n_jobs;i++)
  {
  cout<<b_time<<" ";
  cout<<"\n waiting time \t";
  for(i=0;i<n_jobs;i++)
  {
  cout<<w_time[i]<<" ";
  cout<<"\n\n avg wait time is: "<<avg<<"mfs":
  }
  };
  int main()
  {
  fcfs f;
  int n;
  cout<<"\n\n\t fcfs";
  cout<<"how many job you entered";
  cin>>n;
  f.job_entry(n);
  f.waist_time();
  getch();
  }


































INPUT/OUTPUT:


Fcfs show how many job you can enter: 3
Enter the burst time of each the job:
Job 1: 20
Job2: 25
Job3: 30
Group t chart-4096::-30745

Avg wait time is: -1365.333374mfs-28807
Avg wait time is:-1365.333374mfs925
Avg wait time is:-1365.333347mfs























RESULT:   Thus the program for FCFS has been successfully executed.










EXPERIMENT  02


AIM: To write a program for shortest job fist(SJF)




PROGRAM:
#include<stdio.h>
#include<iostream.h>
#include<conio.h>

  class sjf
  {
  int b_time[10];
  int w_time[10];
  int n_jobs;
  float avg;
  public:
  sjf()
  {
  int n_jobs=0;
  avg=0;
  }
  void job_entry(int n)
  {
  n_jobs=n;
  cout<<"enter the burst time for each job";
  cout<<"\n";
  for(int i=0;i<n_jobs;i++)
  {
  cout<<"\n jobs"<<i+1<<":";
  cin>>b_time[i];               
  }
  sorting(b_time,n);
  }
  void sorting(int b_time[],int n)
  {
  for(int i=0;i<n;i++)
  {
  for(int j=i+1;j<n;j++)
  {
  if(b_time[j]<b_time[i])
  {
  int temp=b_time[i];
  b_time[i]=b_time[j];
  b_time[j]=temp;
  }
  }
  }

  void wait_time(void)
  {
  for(int i=0;i<n_jobs;i++)
  {
  w_time[i]=0;
  for(int j=0;j<i;j++)
  {
  w_time[i]=w_time[i]+b_time[j]
  }
  avg=avg+w_time[i];
  }
  cout<<"\n\t\t grant chart";
  cout<<"\n burst time\t\t";
  for(i=0;i<n_jobs;i++)
  cout<<" "<<b_time[i]<<" ";
  cout<<"\n waiting time \t\t";
  for(i=0;i<n_jobs;i++)
  cout<<"\n\n the averag waiting time is: "<<avg<<"ms";
  }
  };
  int main()
  {
  sjf s;
  int n;
  clrscr();
  cout<<"\n\n\t shortest job first";
  cout<<"\n\n how many jobs going to be executed";
  cin>>n;
  s.job_entry();
  s.wait_time();
  getch();
  }
 












INPUT/OUTPUT:

Shortest job first
How many jobs you enter 3
Job1: 6
Job2: 4
Job3: 8



Grant chart
Burst time                                                6:4:8
Waiting time                                           0:4:10
The average waiting time is                 4.66666667ms


















RESULT:    Thus the program for SJF can be executed successfully.












EXPERIMENT 03

AIM: Write the program for priority scheduling




Table:
PROCESS
BURST TIME
PRIORITY

P1
10
3
P2
1
1
P3
2
4
P4
1
5
P5
5
2




PROCESS
BURST TIME
WAIT TIME
TURN AROUND TIME

P1
10
6
16
P2
1
0
1
P3
2
16
18
P4
1
18
19
P5
5
1
6








PROGRAM:

#include<iostream.h>
#include<conio.h>
class priority
{
public:
int p[25],ser[25],pri[25],pri1[25],wait[25],i,j,j,n;
double awt,fat,s;
void get()
{
cout<<"\n enter job:";
cin>>n;
for(i=0;i<n;i++)
{                   
cout<<"\n enter the burst time for process"; p["<<i+1<<"];
cin>>ser[i];
cout<<"\n enter the priority level"; p["<<i+1<<"];
cin>>pri[i];
pri[i]=pri[i];
p[i]=i;
}
}
void calculate()
{
int temp;
for(i=0;i<n;i++)
{
for(j=0;j<=(n-i-1);j++)
{
if(pri[j]>=pri[j+1])
{
temp=pri[j];
pri[j]=pri[j+1];
pri[j+1]=temp;
}
}
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
if(pri[i]==pri[j])
{
if(i==0)
{
wait[i]=0;
awt=0;
tat=ser[i];
temp=ser[j];
}
else
{
wait[i]=wait[i+1]+temp;
temp=ser[i];
awt+=wait[i];
tat+=ser[i]+wait;
}
}
}
awt=awt/n;
tat=tat/n;
}
void put()
{
wait[0]=0;
cout<<"\n\n scheduling order";
cout<<"\n PID"<<"\t priority"<<"\t service temp"<<"\t wait time";
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(pri[i]==pri[j])
cout<<"\n"<<p[j]+1<<"\t"<<pri[i]<<"\t\t"<<ser[j]<<"\t\t"<<wait[i];
}
}
cout<<"\n\n average waiting time is: "<<awt<<"ms";
cout<<"\n average turn aound time is: "<<tat<<"ms";
}
};
void main()
{
priority p;
clrscr();
p.get();
p.calculate();
p.put();
getch();
}









INPUT/OUTPUT:

Enter the no. of jobs=3
Enter  the burst time for the process p[1]=6
Enter the priority of process p[1]=3
Enter the burst time for process p[2]=6
Enter the priority of process p[2]=1
Enter the burst time for the process p[3]=7
Enter the priority of process[3]=2

Scheduling order
PID                                    priority                            service time                                      wait time
2                                              1                                              6                                                              0
2                                         1                                          6                                                       6
3                                         2                                          7                                                    12


Average time: 8ms
Average time around time:  16.333333ms















RESULT:   Thus the program for the priority scheduling has been executed successfully.













EXPERIMENT -04

AIM:  Write a program for robin scheduling

TABLE:


PROCESS


BURST TIME
P1
24
P2
7
P3
3






GRANTT CHART:

P1
P2
P3
P1
P2
P1
P1
P1
P1
P1
0           4             8             11           15          18          22           26          30         34      38
PROGRAM

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class round
{
int wt,st[20],com[20],brust[20],executed[20];
int tq,n;
float avg;
            public:
            void getdata();
            void calculate();
};
            void round::getdata()
            {
            cout<<"\n ENTER THE NUMBER OF PROCESS:";
            cin>>n;
            cout<<"\n ENTER THE BURST TIME FOR EACH PROCESS:\n";
            for(int i=1;i<=n;i++)
                        {
                        cout<<"\n JOB"<<i<<":";
                        cin>>brust[i];
                        }
                        cout<<"\n ENTER THE TIME QUANTUM:";
                        cin>>tq;
            }
            void round::calculate()
            {
            int flag,i;
            avg=0,wt=0;
            for(i=1;i<=n;i++)
            executed[i]=0;
            flag=1;
            cout<<"\n PROCESS  \tSTARTING TIME \tCOMPLETION TIME";
            while(flag==1)
            {
            flag=0;
            for(i=1;i<=n;i++)
                        {
                        if(brust[i]>tq)
                        {
                        st[i]=wt;
                        if(executed[i]==1)
                        avg=avg+st[i]-com[i];
                        else
                        avg=avg+st[i];
                        wt=wt+tq;
                        com[i]=wt;
                        brust[i]=brust[i]-tq;
                        flag=1;
                        executed[i]=1;
                        cout<<"\n PROCESS"<<":"<<i<<"\t"<<st[i]<<"\t\t\t"<<com[i];
                        }
                        else if(brust[i]>0)
                                    {
                                    st[i]=wt;
                                    if(executed[i]==1)
                                    avg=avg+st[i]-com[i];
                                    else
                                    avg=avg+st[i];
                                    wt=wt+brust[i];
                                    com[i]=wt;
                                    cout<<"\n PROCESS"<<":"<<i<<"\t"<<st[i]<<"\t\t\t"<<com[i]<<"completed";
                                    brust[i]=0;
                                    executed[i]=1;
                                    }
                        }
            }
            avg=avg/n;
            cout<<"\n\n THE AVERAGE WAITING TIME IS:"<<avg<<"\ms";
            }
            void main()
            {
            clrscr();
            round r;
            cout<<"\n\n\t\t\t ROUND ROBIN SCHEDULING \t\t\t:";
            r.getdata();
            r.calculate();
            getch();
            }




INPUT:

Enter the no of jobs=3
Enter the burst time for process p[1]=3
Enter the priority process p[1]: 3
Enter the burst time for  process p[2]=8
Enter the priority process p[2]:1
Enter the burst time for the process p[3]:6
Enter the priority process p[3]:2
                                                       

OUTPUT:

SCHEDULING
PID
PRIORITY
SERVICE TIME
WAIT TIME
2
1
8
0
3
2
6
8
1
3
10
16

Average waiting time: 8ms
Average turnaround time: 12.66667 ms







RESULT:  Thus the program for robin scheduling has been executed successfully

EXPERIMENT-05

Aim:               To write a C++ program for implementing Banker’s algorithm.







TABLE:
                                                                                                                                                Available=3

PROCESS

MAX NEED
ALLOCATED
NEED
P0
10
5
5
P1
4
2
2
P2
9
2
7


















Program:

#include<iostream.h>
#include<conio.h>

class BankerAlgo
{
            private:
                        int allocated[50][50],max[50][50],available[50];
                        int need[50][50];
                        int flag[50];
                        int m,n;
                        int i,j;

            public:

            BankerAlgo()
            {
                         cout<<"\n\a Enter the Row for Allocation and Maximum Matrix , Please !! : ";
                         cin>>m;
                         cout<<"\n\a Enter the Column for Allocation and Maximum Matrix , Please : ";
                         cin>>n;

                            /* Input the Allocation and Maximum matrix by the user */

                         cout<<"\n\a Allocation Matrix ("<<m<<" x "<<n<<")\n";
                         for(i = 0;i < m;i++)
                         for(j = 0;j < n;j++)
                                    cin>>allocated[i][j];

                         cout<<"\n\a Maximum Matrix ("<<m<<" x "<<n<<")\n";
                         for(i = 0;i < m;i++)
                         for(j = 0;j < n;j++)
                                    cin>>max[i][j];

                         cout<<"\n\a Available\n";
                         for(i = 0;i < n;i++)
                         {
                                    cin>>available[i];
                         }

            }

            void MakeNull()
            {
                        for(i = 0;i < 50;i++)
                                    flag[i] = 0;
            }



                        /* Subtraction - Allocating the resource (C-A) */



            void Need()
            {
                        cout<<"\nNeed Matrix ["<<m<<" X "<<n<<"]\n";
                        for(i = 0;i < m;i++)
                        {
                                    for(j = 0;j < n;j++)
                                    {
                                         need[i][j] = max[i][j] - allocated[i][j];
                                         cout<<need[i][j]<<"\t";
                                    }
                                    cout<<"\n";
                        }
            }

                                    /* Validating the Resource Allocation */
            int Check(int column)
            {
                        for(i = 0;i < n;i++)
                                    if(need[column][i] > available[i])
                                                return 0;
                                                return 1;
            }


                          /* Adding to the Available Matrix */


            void AddResource(int column)
            {
                        for(int i = 0;i < n;i++)
                                    available[i] = available[i] + allocated[column][i];
            }

            void Process()
            {
                        int t,k,l;
                        int temp = 0;
                        MakeNull();

                        cout<<"\nSafety Sequence :";
                        for(k = 0;k < 3;k++)
                        {
                                    temp = 0;
                                    for(l = 0;l < m;l++)
                                    {
                                                if(flag[l] == 0)
                                                {
                                                            temp = 1;
                                                            if(Check(l) == 1)
                                                            {
                                                                        AddResource(l);
                                                                        flag[l] = 1;
                                                                        cout<<" P"<<l;
                                                            }
                                                }
                                    }
                        }
                        if(temp == 0)
                                    cout<<"\n\nSystem in Safe State";
                        else
                                    cout<<"\n\nSystem in UnSafe State";
            }
};

int main()
{
            clrscr();
            BankerAlgo B;
            B.Need();
            B.Process();
            getch();

}



INPUT/OUPUT


 Enter the Row for Allocation and Maximum Matrix , Please !! : 2

 Enter the Column for Allocation and Maximum Matrix , Please : 2

 Allocation Matrix (2 x 2)
1
2
3
4

 Maximum Matrix (2 x 2)
5
6
7
8

 Available
5
4

Need Matrix [2 X 2]
4       4
4       4

Safety Sequence : P0 P1

System in Safe State










RESULT:  Thus the program for bankers algorithm has been successfully executed.


EXPERIMENT NO. 6

AIM:  Write a program for Best Fit Algorithm



TABLE:

           

                                                                                                          











6KB





14KB




19KB



11KB




10KB














PROGRAM:

#include<iostream.h>
#include<conio.h>
void main()
{
int m[100],f,i,j,n,flag;
clrscr();
cout<<"enter the size of the array";
cin>>n;
for(i=0;i<n;i++)
{
cin>>m[i];
}
cout<<"enter the size of process";
cin>>f;
for(j=0;j<n;j++)
{
if(m[j]==f)
{
cout<<"process is matched";
flag=0;
break;
else
flag=1;
}
if(flag==1)
cout<<"process not matched";
}
getch();
}













INPUT/OUTPUT:

Enter the size of the array 5
6
14
19
11
10

Enter the process 19
Process is matched
















RESULT:   Thus the program for best fit algorithm has been executed successfully.
















EXPERIMENT NO. 7

AIM: Write a program for paging algorithm




TABLE:

0
0
1
7
2
5
3
9
4
3






















PROGRAM:
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
clrscr();
int page[5];
int s,i,j,a,frame[10];
randomize();
for(i=0;i<10;i++)
{
asd:
a=random(5);
for(j=1;j<i;j++)
{
if(a==frame[j])
goto asd;
}
if((i%2)==1)
{
frame[i]=a;
page[a]=i;
}
else
{
frame[i]=111;
}
}
for(i=0;i<5;i++)
cout<<i<<"\n";
cout<<"\n page table \n";
for(i=0;i<5;i++)
{
cout<<i<<"\t"<<page[i]<<"\n";
}
cout<<"\t post page \n";
for(s=0;s<10;s++)
cout<<s<<"\t";
cout<<frame[s]<<"\n";
}
getch();


INPUT/OUTPUT:



0                                            2
1                                            111
2                                            3
3                                            111
4                                            0
5                                            111
6                                            1
7                                            111
8                                            1
9                                            111

















RESULT:    Thus the program for paging has been successfully executed.
















EXPERIMENT  08
AIM:  Write a program for page replacement

PROGRAM:
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main()
{
clrscr();
int aa=0,frame[3],i,a[5],pt=0;
cout<<"enter the element of the string";
for(i=0;i<3;i++)
frame[i]=-1;
for(i=0;i<5;i++)
cin>>a[i];
for(i=0;i<5;i++)
{
if(pt==3)
{
pt=0;
}
if(a[i]==frame[pt])
{
frame[pt]=a[i];
}
frame[pt]=a[i];
aa++;
{
pt++;
}                                          
printf("\n page fault is %d",aa);
getch();
}


INPUT/OUTPUT:
Enter the elements in the string
1   2   3   2   1
Page fault is 3













RESULT:  Thus the program for page replacement has been successfully executed.











EXPERIMENT – 9

AIM:  Write a program for producer consumer problem


PROGRAM:

#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
class pcp
{
public:
  int count;
  int buffer[6];

pcp()
{
count=0;
}
~pcp()
{
count=0;
}
void insert();
void remove();
int full();
};
int pcp::full()
{
  if (count==5)
  {
    return(1);
  }
  else
  {
  return(0);
  }
}

void pcp::insert()
{
  if(full())
  {
  cout<<"no data can be inserted";
  }
  else
  {
  cout<<"enter data to be inserted";
  cin>>buffer[count];
  count++;
  }
  }

    void pcp::remove()
    {
    int a;
    if (full())
    {
    for(int i=0;i<5;i++)
    {
    a=buffer[count];
    cout<<"element remove is: "<<a<<endl;
    count--;
    }
    }
    else
    {
    cout<<"not pssible";
    }
    }
    void main()
    {
    int n;
    pcp z;
    clrscr();
    while(1)
    {
    cout<<"\n operation";
    cout<<"\n 1. add data";
    cout<<"\n 2. remove data";
    cout<<"\n 3. exit";
    cout<<"\n enter your choice";
    cin>>n;
    switch(n)
    {
      case 1:
      z.insert();
      break;
      case 2:
      z.remove();
      break;
      case 3:
      exit(1);

      cout<<"choice is invalid";
      }
    }
    getch();
    }

































INPUT/OUTPUT:


Operations
1.add
2.remove
3.exit

Enter your choice 1
Enter data to be inserted 2
Enter your choice 2
Not possible























RESULT:   Thus the program for producer consumer problem has been executed successfully














networking Btech. practical cse programs


EXPERIMENT-01
TCP & UDP
TCP- Transmission Control Protocol
TCP is one of the main protocols in TCP/IP network. TCP enables two hosts to establish a connection and exchange steam of data. TCP guarantees delivery of data and also ensure that they are sent in the same order. The unit of data transferred is called a steam which is simply a sequence of bytes.
Being connection oriented means that before actually transmitting data, we must open the connection between the two end points. The data transfer cannot take place before both ends have agreed upon the connection. The connection can be closed from either side.
Being steream oriented means that the data is anonyumous sequence of bytes. There is nothing to make data boundaries apparent. The data sent is without any error and in correct order.

ADVANTAGES OF TCP:
1.    The operating system does all the work. No need to have the same bugs in your code that everyone else had, its all been already figured out.

2.   It guarantees three things:-
1)   That your data gets there.
2)   It gets in order.
3)   It gets without duplication.
3.    TCP has good throughput on a modem or LAN.

DISADVANTAGES OF TCP:
1.   The operating system may be buggy and you can’t escape that. You have to put up with it.
2.   TCP has no block boundaries; we need to create our own.
3.   TCP cannot be used for broadcast or multicast.

UDP:
 It stands for User Datagram Protocol, a connectionless protocol that like TCP runs on the top of the I/P network. Unlike TCP/IP, UDP/IP provides a few error recovery services, offering instead a direct way to send and receive datagrams over an IP network. It’s used primarily for broadcasting messages over an I/P network. It’s used primarily for broadcasting messages over a network.
UDP provides a connection-less host-host communication path. UDP has minimal overhead; each packet on the network is composed of a similar header and user data. It is called a UDP datagram.
UDP is connectionless. It means that a datagram can be sent at any moment without prior advertising negotiation or preparation. UDP is unreliable protocol. There is absolutely no guarantee that the datagram will be delivered to the destination host.

ADVANTAGES OF UDP
1)   It does not restrict you to a connection based communication modem.
2)   All flow control, making the transactions logging etc is up to user programs.
3)   Broadcast and multicast transmission are available.

DISADVANTAGES OF UDP:
1)   There is no guarantee with UDP, a packet may not be delivered, or delivered twice or delivered out of order.
2)   It has no flow control. Implementations are the duty of user program.


COMPARISON:-
TCP
UDP
·       Connection oriented
·       Reliability in delivery of messages.
·       keep track of order


·       Connection less
·       No attempt to fragment messages.
·       In case of error message is retransmitted.
































EXPERIMENT-02

FTP, HTTP & TELNET

FTP:-
FTP is an acronym for File Transfer Protocol. As the name suggests FTP is used to transfer files between computers on a network. You can use FTP to exchange files between computers accounts, transfer files between an account and a desktop computer or access online software archives.

WAY TO USE FTP:
Web-Browser:  you can use a web browser to connect to FTP addresses exactly as you would to connect to HTTP addresses. To use it we may write

Graphical FTP client:-
It simply file transfers by allowing you to drag and drop files icon between windows. When you open the program enter the name of the FTP host and your username and password.

MODES OF DATA TRANSFER:-
·       Stream Mode: data is sent as a continuous stream, relieving FTP from doing any processing.
·       Block Mode: FTP blocks the data into several blocks and then passes it to TCP.
·       Compressed Mode: Data is compressed using a single algorithm.



HTTP:
It stands for Hyper Text Transfer Protocol.
Computer on world wide web use the hypertext transfer protocol to talk with each other. The HTTP provides a set of instructions for accurate information exchange. The HTTP connects computer network and allows them to communicate.

VERSIONS:
The first version of HTTP refused to as HTTP/0.9 was a simple protocol for raw data transfer across the internet HTTP/1.0 improved the protocol by allowing messages about the data transfers. The specifications defines the protocol as HTTP/1.1 in order to ensure reliable implementations of its features.

HTTP SESSION STATE:
HTTP is a stateless protocol. The advantages of stateless protocol is that hosts do not need to retain information about users between requests. But a web application must be written to track users progress from state to state. A common method to solve this is send and receive cookies.

TELNET:

TELNET is a user command and an underlying TCP/IP protocol for accessing remote computers. Through telnet, an administrator or another user can access someone elses computer remotely. With telnet you log on as a regular user with whatever privilages you have been granted.

The term telnet may also refer to the software that implements the client part of the protocol.

THE APPLICATIONS ARE:-
1.   Enterprise network
2.   Internet games
3.   Administration of network element.


HOW TELNET WORKS:
          TELNET uses a software installed on your computer to create a connection with the remote host. The telnet client at your command will send a request to the server. The telnet client will establish a connection to the host thus making your computer a virtual terminal and allowing you to complete the access















                             EXPERIMENT-03

AIM:  To perform the client-server communication using TCP/IP protocol.




Algorithm:

1.   Received the messsageFrom user.
2.   Send the message to server
3.   Receive the acknowledgement from server.
4.   Display on server side.

















PROGRAM:

import java.io.*;
import java.net.*;
classclienttcp
{
public static void main(String argv[]) throws Exception
{
String sentence;
String modifiedSentence;
BufferedReaderinFromUser=new BufferedReader(new InputStreamReader(System.in));
Socket clientSocket = new Socket("192.168.3.111",6789);
DataOutputStreamoutToServer=new DataOutputStream(clientSocket.getOutputStream());
BufferedReaderinFromServer=new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
sentence=inFromUser.readLine();
outToServer.writeBytes(sentence + '\n');
modifiedSentence=inFromServer.readLine();
System.out.println("FROM SERVER:"+modifiedSentence);
clientSocket.close();
}
}









import java.io.*;
import java.net.*;
classstcp
{
public static void main(String args[])throws Exception
{
String clientSentence;
String capatalizedSentences;
ServerSocketWelcomeSocket = newServerSocket(6789);
while(true)
{
SocketConnectionSocket = WelcomeSocket.accept();
BufferedReader inform client = new BufferedReader(new InputStreamReader(ConnectionSocket.getInputStream()));
DataOutputStram out to client = new Data Output Stream(ConnectionSocket.getOutputStream());
ClientSentence = inform Client.readline();
System.out.println("Recieved"+clientSentence);
Capatalized Sentence = ClientSentence to uppercase()+'\n\;
outToclient.WriteBytes(CapatalizedSentence);
}
}
}







INPUT/OUTPUT:

CLIENT SIDE:
C:\jdk1.6\bin\javac ctcp.java
C:\jdk1.6\bin>java ctcp
Hello

FROM SERVER: HELLO

Server side:
C:\jdk1.6\bin\javac stcp.java
C:\jdk1.6\bin>java stcp
Received:















RESULT: The client server program has been successfully executed.
                   EXPERIMENT -04
AIM: To perform  the client server using UDP.

Algorithm:
1.   Send the request to server.
2.   Receive the retrieve data from server.
3.   Display the message.

























Program:
Client:


import java.net.*;
import java.io.*;
classudpclient
{
public static void main(String args[])throws Exception
 {
DatagramSocketdsoc=new DatagramSocket(24);
byte buff[]=new byte[1024];
DatagramPacketdpack=new DatagramPacket(buff,buff.length);
dsoc.receive(dpack);
System.out.println(new String(dpack.getData()));
  }
 }














Server:

importjava.util.*;
import java.io.*;
import java.net.*;
classudpser
{
public static void main(String args[])throws Exception
  {
DatagramSocketdsoc=new  DatagramSocket(5217);
InetAddress host=InetAddress.getLocalHost();
    String str=(new Date()).toString();
bytebuf[]=str.getBytes();
DatagramPacketdpack=new DatagramPacket(buf,buf.length,host,24);
dsoc.send(dpack);
dsoc.close();
   }
  }













INPUT/OUTPUT:
C:\jdk1.6\bin\javac Udpserver.java
C:\jdk1.6\bin\java  Udpserver
Wed Aug25 11:05:15 IST 2010






















RESULT: Thus the program has been successfully executed.

                             EXPERIMENT-05

AIM: To fetch date and time from server using TCP/IP     protocol.

Algorithm:
SERVER:
1.   Make the connection.
2.   Store the date and time in buffer
3.   Transfer the date and time to client.
4.   Close the connection.


Client:
1.   Make the connection.
2.   Store the date and time in buffer.
3.   Receive the date from server.
4.   Close the connection.













PROGRAM:

Server:

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

classdateser
{
public static void main(String args[])throws Exception
{
ServerSocket s=new ServerSocket(5217);

while(true)
 {

System.out.println("waiting for connection.......");
 Socket soc=s.accept();
DataOutputStream out=new DataOutputStream(soc.getOutputStream());
out.writeBytes("Server Date"+(new Date()).toString()+"\n");
out.close();
soc.close();
 }
 }
 }






Client:

import java.io.*;
import java.net.*;
classdateclient
{
public static void main(String args[])
throws Exception
{
Socket soc=new Socket
(InetAddress.getLocalHost(),5217);
BufferedReader in=new BufferedReader
(newInputStreamReader(soc.getInputStream()));
System.out.println(in.readLine());
}
}













INPUT/OUTPUT:

C:\documenta and setings\cd1
C:\>cd jdk1.6
C:\>jdk1.6> cd bin
C:\>jdk1.6>bin>javac dateclient.java
C:\jdk1.6>bin>java dateclient
Server date Tue 1 Sept 22:14:52 IST

SERVER:
C:\documents and settings\cd
C:\jdk1.6>cd bin
C:\>jdk1.6>bin>javac dateser.java
C:\jdk1.6>bin>java dateser
Waiting for connection……












RESULT: The program to fetch date and time from server using TCP/IP protocol have been fetched successfully.



SMTP AND POP3

SMTP:
It stands for simple mail transfer protocol. It is an internet standard for electronic mail transmission across internet protocol networks. It can be said as it is the set of procedures needed for users to send mail from their networked computer to remote computer.

PROTOCOL OVERVIEW:
SMTP is a text based protocol in which a mail sender communicates with a mail receiver by issuing command strings and supplying necessary data over a reliable ordered data stream channel.
          An SMTP session consists of commands originated by an SMTP client and corresponding responses from the server. An SMTP transactions consists of three commands.
1.   MAIL command to return address.
2.   RCPT to establish a recipient of this message.
3.   DATA to send the message text.

SMTP Vs. MAIL RETRIEVAL
SMTP is a delivery protocol only. It cannot pull messages from a remote server on demand other protocol such as POP are especially designed for retrieving messaged.





POP3 (Version 3)
          It stands for Post Office Protocol. It is an application layer internet standard protocol used by local email clients to retrieve e-mail from a remote server over a TCP/IP connection. POP supports simple download and delete requirements for access to remote mail boxes. Although most POP clients have an option to leave mail on server after download.
          A POP3 mail server receives e-mails and filters than into the appropriate user folder when a user connects to the mail server to retrieve his mail the messages are downloaded from mail server to the users hard disk.
 When you configure your email client such as outlook or mail you will need to enter the type of mail your email accounts users. This will be POP server.

          Still most mail servers use the POP3 mail protocol because it is simple and well supported.













                             EXPERIMENT-07

AIM: To perform chatting application using UDP Protocol.


ALGORITHM:

Client:
1.   Receive the message from the user.
2.   Send the server.
3.   Display on server side.

Server:
1.   Receive message from client.
2.   Display the message

















PROGRAM:

import java.io.*;
import java.net.*;
importjava.util.*;
classser
{
public static void main(String args[])throws Exception
{
BufferedReaderinFromUser=new BufferedReader(new InputStreamReader(System.in));
DatagramSocketserverSocket=new DatagramSocket(5217);
byte[ ] receiveData=new byte[1024];
byte[ ] sendData=new byte[1024];
while(true)
{
DatagramPacketreceivePacket=new DatagramPacket(receiveData,receiveData.length);
serverSocket.receive(receivePacket);
String sentence=new String(receivePacket.getData());
System.out.println("received"+sentence);
InetAddressIPAddress=receivePacket.getAddress();
int port=receivePacket.getPort();
String capitalizedSentence=inFromUser.readLine();
sendData=capitalizedSentence.getBytes();
DatagramPacketsendPacket=new DatagramPacket(sendData,sendData.length,IPAddress,port);
serverSocket.send(sendPacket);
}
}                             
}

CLIENT:

import java.io.*;
import java.net.*;
importjava.util.*;
class cli
{
public static void main (String args[ ]) throws Exception
{
BufferedReader user = new BufferedReader (new InputStreamReader(System.in));
DatagramSocketclientSocket=new DatagramSocket();
InetAddressipaddress = InetAddress.getByName("localhost");
byte[ ] sendData=new byte[1024];
byte[ ] receiveData= new byte[1024];
while(true)
{
String sentence= user.readLine();
sendData=sentence.getBytes();
DatagramPacketsendPacket=new DatagramPacket(sendData,sendData.length,ipaddress, 5217);
clientSocket.send(sendPacket);
DatagramPacketreceivePacket=new DatagramPacket(receiveData,receiveData.length);
clientSocket.receive(receivePacket);
String modifiedSentence=new String(receivePacket.getData());
if(modifiedSentence=="terminate")
{
clientSocket.close();
}
System.out.println("from server" + modifiedSentence);
}
}
}



                            


































INPUT/OUTPUT:
C:\jdk1.6\bin>javac ser.java
C:\jdk1.6\bin>java ser
Received hello
Hi received hows life

C:\jdk1.6\bin>javac cli.java
Hello
From server hi
hows life















RESULT: the program has been successfully executed.
        SINGLE SOURCE SHORTEST PROGRAM

Aim: write a program to implement the single source    shortest path algorithm