28 February, 2015

Network Programing: Practical#3

Aim: Programs related to message queues.
Theory:
//Program for Sender side
#include "sys/types.h"
#include "sys/ipc.h"
#include "sys/msg.h"
#include "stdio.h>"
#include "string.h"
#include "stdlib.h"

#define MAXSIZE 128

void die(char *s)
{
  perror(s);
  exit(1);
}

struct msgbuf
{
    long    mtype;
    char    mtext[MAXSIZE];
};

void main()
{
    int msqid;
    int msgflg = IPC_CREAT | 0666;
    key_t key;
    struct msgbuf sbuf;
    size_t buflen;

    key = 1234;

    if ((msqid = msgget(key, msgflg )) < 0)   /*Get the message queue ID for the given key*/
      die("msgget");

    //Message Type
    sbuf.mtype = 1;

    printf("Enter a message to add to message queue : ");
    scanf("%[^\n]",sbuf.mtext);
    getchar();

    buflen = strlen(sbuf.mtext) + 1 ;

    if (msgsnd(msqid, &sbuf, buflen, IPC_NOWAIT) < 0)
    {
        printf ("%d, %li, %s, %li\n", msqid, sbuf.mtype, sbuf.mtext, buflen);
        die("msgsnd");
    }

    else
        printf("Message Sent\n");

    exit(0);
}


//Program for Receiver side
#include "sys/types.h"
#include "sys/ipc.h"
#include "sys/msg.h"
#include "stdio.h>"
#include "string.h"
#include "stdlib.h" 
#define MAXSIZE 128
void die(char *s)
{
  perror(s);
  exit(1);
}
static struct msgbuf
{
    long    mtype;
    char    mtext[];
};

void main()
{
    int msqid;
    key_t key;
   struct msgbuf rcvbuffer;
    key = 1234;
    if ((msqid = msgget(key, 0666)) < 0)
      die("msgget()");
     //Receive an answer of message type 1.
    if (msgrcv(msqid, &rcvbuffer, MAXSIZE, 1, 0) < 0)
      die("msgrcv");
    printf("%s\n", rcvbuffer.mtext);
    exit(0);
}



Firstly run this program on unix system then write it on the files...Take screen shots and then paste on the files for output...Do it in proper way and also understand the proper functioning... This is for I1 group only.....

23 February, 2015

Lect-11(23/2/2015)

Socket Programming
IP Address: IP address is used to identify the host on a network.
Port Address: Port address is used to identify the process on the host. For example, port 80 is used for HTTP traffic, port 23 is used for telnet.

What is Socket?
Sockets are a method for communication between a client program and a server program in a network. A socket is defined as "the endpoint in a connection. Sockets are created and used with a set of programming requests or "function calls" sometimes called the sockets application programming interface (API). The most common sockets API is the Berkeley UNIX C interface for sockets. Sockets can also be used for communication between processes within the same computer.
A socket is one end-point of a two-way communication link between two programs running on the network.

On the client-side: The client knows the hostname of the machine on which the server is running and the port number on which the server is listening. To make a connection request, the client tries to rendezvous with the server on the server's machine and port. 

If everything goes well, the server accepts the connection.


On the client side, if the connection is accepted, a socket is successfully created and the client can use the socket to communicate with the server.

Why need Socket?
A socket is an IP address and a port address. Sockets exist within communication domains and allow for bi-directional, reliably, and sequenced data flow. When used in the client/server model, it allows programs such as FTP and Telnet to function properly.

Example: A Telnet server listens at port 23 for service requests. Telnet will remain inactive until a client connects to the servers IP address. This request would be passed up the stack to the appropriate port (23). At that moment, the server would wake up and perform whatever has been requested by the client.
Therefore, without an IP address, the client would not be able to find the server or without the correct port, the client couldn’t find the need server services. 

16 February, 2015

MCQ answers of Minor-I

(1) XDR stands for
 a)          External Data Row                                                  b) Exit Data Row
              c)    External Data Representation                                    d) Exit Data Representation

(2) At a particular time the value of the counting semaphore is 15. It will become 22 after                            
        a) 8P and 2V                   b) 4V only                      c)  7V Only              d) 4V and 3P
(3) At a particular time the value of the counting semaphore is 21. After 5P and  2V  
       operation, what will be      the value for Semaphore?
        a) 17                               b) 18                                c) 19                          d)  21
(4) The example of Open Source Code is
          a)      Window 8             b) Linux                 c) Windows NT           d) All of the above

(5) Which interposes communication mechanism is fastest
       a) Shared Memory              b)     Pipes                           c) Message Queue       d) FIFO
(6)  RPC allows a computer program to cause a subroutine to execute in
       a) its own address space     b) another address space     c) both (a) and (b)      
       d) none of the mentioned
(7) In the  blocking send
      a) the sending process keeps sending until the message is received
      b) the sending process sends the message and resumes operation
      c) the sending process keeps sending until it receives a message
      d) None of these
(8) Unnamed pipes is known as
             a)      FIFO               b) Message Queue            c) Both a & b              d) None of the above

(9) Pipelining improves CPU performance due to
     (a) reduced memory access time                                    (b) increased clock speed
     (c) the introduction of parallelism                                  (d) additional functional units
(10) Which of the following is not the function of Micro kernel?
     (a) File management                                                (b) Low-level memory management
     (c) Inter-process communication                               (d) I/O interrupts management
(11) Information about a process is maintained in a _________
      (a) Stack                                                                (b) Translation Look aside Buffer
      (c)  Process Control Block                                  (d) Program Control Block
(12) The program is known as _________ which interacts with the inner part of called kernel.
        (a) Compiler                 (b)  Device Driver              (c) Protocol                   (d)  Shell
(13) Inter process communication can be done through __________.
        (a)  Mails                       (b) Messages                        (c)  System calls        (d) Traps
(14) Mail services are available to network users through the _______ layer.
        (a) Data link                 (b) Physical                          (c) Transport              (d) Application
(15) As the data packet moves from the upper to the lower layers, headers are __
        (a) Added              (b) Removed                       (c) Rearranged                  (d) Modified
(16) The convention and rules used in such communications are collectively known as
        (a) Peer           b)Layer protocol              (c) Network                  (d) None of these

13 February, 2015

MCQ-II, Review

 1. TCP/IP suite was created by
      a)  IEEE              b) Department of defense    c ) Open source        d)None of above
2.Which protocol ensures reliable delivery
   a) TCP                 b) UDP                         c)Both of above       d)None of above
3. Delimiting and synchronization of data exchange is provided by
      a) Application layer        b) Session layer                c) Transport layer    d) Link layer
4. Node to node delivery is done in which layer.
      a) Physical Layer     b) Data Link Layer     c) Network Layer     d) Transport Layer
 5. An IPC facility provides at least one operations
   a) write message   b) delete message      c) send message     d) None
6. RPC provides a(an) _____on the client side, a separate one for each remote procedure.
     a) stub         b) identifier         c) name      d) process identifier
7. In the client/server architecture, the component that processes the
     request and sends the  response is-
     a)  Network             (b)  Client                (c)  Server               (d)  Protocol 
8. In 3-tier client/server applications, the business logic lies at-------
   (a) The client   (b)  The Database Server
    (c) Divided between client and server alternatively     d)Middle Tier
9. With a ______, the client passes requests for file records over a network.
       a) File server     b) Database server   c) Transaction server  d) Groupware server.
10. The bidirectional flow is known as
     a) Simplex        b) Half duplex     c) full duplex     d)none
11. In POSIX, P stands for
     a) Performance      b) Portable      c) primary       d) planning
12. Flow of control is known as
     a) XDR         b)Signal  c) RPC     d) Process
13) PID is
    a) Normal Function     b)System call   c)method   d) both a & b
14) Semaphore is
    a) IPC        b) RPC       c) XDR       d) none of the above
15) At a particular time the value of the counting semaphore is 37. It will become 35 after ?
     a. 3P and 2V                    b) 3V and 5P                c) 4P and 7V            d) 3V and 3P
16) The value of semaphore is 32.After 11P and 20V operation, what will
       be the value for Semaphore?
       a)      40                           b) 41                      c) 42                       d) no change
17)  Bounded capacity is
     a) Finite Size  b) Infinite Size   c) Both of them   d)None of above
18) ICMP is primarily used for
     a) error and diagnostic functions  b) addressing  c) forwarding  d) none of the mentioned
19) ISO stands for
    a) Internal structure organization  b) International Standard Organization
    c) Both    d)None
20) OSI model start with which layer
    a) Physical            b)Network         c)Transport          d) Application

09 February, 2015

Updated Practical#2

Aim: Programs related to interposes communication using pipes.
(RHS) Theory: Program You know 
               a) Sender.c
               b) Receiver.c 
(LHS) Output:




//Sender.c File
#include"stdio.h"
#include"sys/stat.h"
#include"fcntl.h"
int main()
{
 char data[100];
 int fd=0, len=0, i=1;
 fd=open("Datapipe",O_WRONLY);
 if(fd==-1)
  {
   printf("\n Receiver process has not created yet");
   return 1;
  }
while(1)
{
 len=read(0,data,100);
 if(len<=1)
  {
    break;
  }
 write(fd,data,len);
}
close(fd);
printf("\n");
return 0;
}


On Next Page
// Receiver.c file
#include"stdio.h"
#include"sys/stat.h"
#include"fcntl.h"
int main()
{
 char data[100];
 int fd=0, len=0, i=1;
 unlink("Datapipe");
 mkfifo("Datapipe",0660);
 fd=open("Datapipe",O_RDONLY);
 if(fd==-1)
  {
   printf("\n Error creating pipe");
   return 1;
  }
while(1)
{
 len=read(fd,data,100);
 if(len<=0)
  {
    break;
  }
 data[len]='\0';
 printf("\nString %d : %s",1,data);
 i++;
}
close(fd);
unlink("Datapipe");
printf("\n");
return 0;
}



LHS:
AIM:………………………………

Compile:
Termianl 1:
 gcc sender.c –o sender.out
 gcc receiver.c –o receiver.out
Run:
Terminal 1:
./receiver.out
Terminal 2:
./sender.out
Now take screen shots after run the program in proper way


MCQ-I Review

Highest Marks: 16.75 out of 20.
Lowest Marks: 1.5 out of 20.

MCQ test on Networking Programming

 Answers are shows as Bold.
1.At a particular time the value of the counting semaphore is 15. It will 
            become 17 after ?
a. 3P and 2V   b) 4V only       c) 4P and 7V               d) 5V and 3P

2.At a particular time the value of the counting semaphore is 25. After 3P and 5V operation, what wil be the value for Semaphore?
      a)      25                    b) 28                c) 27                d). 26

3.Which of the following is true in the context of Inter-process communication:
 a). It is like a user defined procedure call.           b). It is like user defined a function call.
 c). It is a system call.                                           d). None of the above

4. Bounded capacity and Unbounded capacity queues are referred to as :
a) Programmed buffering                                b) Automatic buffering
c) User defined buffering                               d) No buffering

5) In the non blocking send
a) the sending process keeps sending until the message is received
b) the sending process sends the message and resumes operation
c) the sending process keeps sending until it receives a message
d) None of these

6) The link between two processes P and Q to send and receive messages is called :
a) communication link                      b) message-passing link
c) synchronization link                        d) All of these

7. Which layer is responsible for process to process delivery?
a) network layer          b) transport layer      c) session layer d) data link layer

8.Transmission data rate is decided by
a) network layer          b) physical layer        c) data link layer         d) transport layer

9. Which one of the following task is not done by data link layer?
a) framing        b) error control            c) flow control                        d) channel coding

10. RPC allows a computer program to cause a subroutine to execute in
a) its own address space b) another address space c) both (a) and (b) d) none of the mentioned

11. RPC is a
a) synchronous operation b) asynchronous operation          c) time independent operation d) none

12. The local operating system on the server machine passes the incoming packets to the
a) server stub b) client stub   c) client operating system       d) none of the mentioned

13. Remote procedure calls is
a) inter-process communication b) a single process c) a single thread d) none of the mentioned.

14……….refers to computing technologies in which the hardware and software components are distributed across a network.
a)Client and Server   b) User and System     c) User and file server  d) User and database server

15. Which of the following is not the correct benefit of distributed computing.
a) Resource sharing                 b) Performance            c) Availability d) Security

16. OSI stands for
D) Open System Interconnection


17 How many layers are in TCP/IP
 a) 7     b) 4      c) 5      d) 3

18.The OSI model start with which layer?
a) Physical Layer         b) Network Layer       c) Application Layer d) Presentation Layer

19.Packets are available in which layer?
a) Physical Layer         b) Network Layer     c) Application Layer   d) Presentation Layer

20. Data Compression is done at which layer?
a) Physical Layer         b) Network Layer       c) Application Layer   d) Presentation Layer

02 February, 2015

Important Program List.

Program List
Q1. Write a shell program to find largest or smallest number among three numbers.
Q2. Write a shell program to show that the given number is odd or even.
Q3. Write a shell program to show that the given year is leap year or not.
Q4. Write a shell program to reverse a number.
Q5. Write a shell program to print  that the given number is palindrome or not.
Q6. Write a shell program to print the given number is prime or not.
Q7. Write a shell program to print factorial number.
Q8. Write a shell program to print fabonacci series.
Q9. Write a shell program to print table.
Q10. Write a shell program to print swapping of two numbers. 

Do practice yourself.