Bcs-052-Ignou Assignment Guru 2017-2018 PDF

Title Bcs-052-Ignou Assignment Guru 2017-2018
Author Chaitanya Kakapuri
Course Bachelor of computer application
Institution Indira Gandhi National Open University
Pages 21
File Size 1.5 MB
File Type PDF
Total Downloads 24
Total Views 570

Summary

BCA MCA BA MA BDP B M B IGNOU ASSIGNMENT GURU Page- 1 ignouassignmentguru /IGNOUASSIGNMENTGURU BCA MCA BA MA BDP B M B ignouassignmentguru Q. A.(a) TCP/IP PROTOCOL SUITE Communications between computers on a network is done through protocol suits. The most widely used and most widely available proto...


Description

BCA MCA BA MA BDP B.COM M.COM B.SC

IGNOU ASSIGNMENT GURU Page-

1

http://www.ignouassignmentguru.com

/IGNOUASSIGNMENTGURU

BCA MCA BA MA BDP B.COM M.COM B.SC

http://www.ignouassignmentguru.com

Q.1. A.1.(a)

TCP/IP PROTOCOL SUITE Communications between computers on a network is done through protocol suits. The most widely used and most widely available protocol suite is TCP/IP protocol suite. A protocol suit consists of a layered architecture where each layer depicts some functionality which can be carried out by a protocol. Each layer usually has more than one protocol options to carry out the responsibility that the layer adheres to. TCP/IP is normally considered to be a 4 layer system. The 4 layers are as follows : 1. 2. 3. 4.

Application layer Transport layer Network layer Data link layer

1. Application layer This is the top layer of TCP/IP protocol suite. This layer includes applications or processes that use transport layer protocols to deliver the data to destination computers. At each layer there are certain protocol options to carry out the task designated to that particular layer. So, application layer also has various protocols that applications use to communicate with the second layer, the transport layer. Some of the popular application layer protocols are :    

HTTP (Hypertext transfer protocol) FTP (File transfer protocol) SMTP (Simple mail transfer protocol) SNMP (Simple network management protocol) etc

TCP is used where a reliable connection is required while UDP is used in case of unreliable connections. TCP divides the data(coming from the application layer) into proper sized chunks and then passes these chunks onto the network. It acknowledges received packets, waits for the acknowledgments of the packets it sent and sets timeout to resend the packets if acknowledgements are not received in time. The term ‘reliable connection’ is used where it is not desired to loose any information that is being transferred over the network through this connection. So, the protocol used for this type of connection must provide the mechanism to achieve this desired characteristic. For example, while downloading a file, it is not desired to loose any information(bytes) as it may lead to corruption of downloaded content.

/IGNOUASSIGNMENTGURU

IGNOU ASSIGNMENT GURU Page-

This layer provides backbone to data flow between two hosts. This layer receives data from the application layer above it. There are many protocols that work at this layer but the two most commonly used protocols at transport layer are TCP and UDP.

2

2. Transport Layer

BCA MCA BA MA BDP B.COM M.COM B.SC

http://www.ignouassignmentguru.com

UDP provides a comparatively simpler but unreliable service by sending packets from one host to another. UDP does not take any extra measures to ensure that the data sent is received by the target host or not. The term ‘unreliable connection’ are used where loss of some information does not hamper the task being fulfilled through this connection. For example while streaming a video, loss of few bytes of information due to some reason is acceptable as this does not harm the user experience much.

3. Network Layer This layer is also known as Internet layer. The main purpose of this layer is to organize or handle the movement of data on network. By movement of data, we generally mean routing of data over the network. The main protocol used at this layer is IP. While ICMP(used by popular ‘ping’ command) and IGMP are also used at this layer.

4. Data Link Layer This layer is also known as network interface layer. This layer normally consists of device drivers in the OS and the network interface card attached to the system. Both the device drivers and the network interface card take care of the communication details with the media being used to transfer the data over the network. In most of the cases, this media is in the form of cables. Some of the famous protocols that are used at this layer include ARP(Address resolution protocol), PPP(Point to point protocol) etc.

TCP/IP CONCEPT EXAMPLE One thing which is worth taking note is that the interaction between two computers over the network through TCP/IP protocol suite takes place in the form of a client server architecture. Client requests for a service while the server processes the request for client. Now, since we have discussed the underlying layers which help that data flow from host to target over a network. Lets take a very simple example to make the concept more clear.

IGNOU ASSIGNMENT GURU Page-

3

Consider the data flow when you open a website.

/IGNOUASSIGNMENTGURU

BCA MCA BA MA BDP B.COM M.COM B.SC

http://www.ignouassignmentguru.com

A.1.(b)

Port Address: There are many application running on the computer. Each application run with a port no.(logically) on the computer. This port no. for application is decided by the Kernal of the OS. This port no. is called port address.

A.1.(c) Definition A three-way handshake is a method used in a TCP/IP network to create a connection between a local host/client and server. It is a three-step method that requires both the client and server

/IGNOUASSIGNMENTGURU

IGNOU ASSIGNMENT GURU Page-

Physical address: Each system having a NIC(Network Interface Card) through which two systems physically connected with each other with cables. The address of the NIC is called Physical address or mac address. This is specified by the mmanufacturer company of the card. This address is used by data link layer.

4

Logical Address: An IP address of the system is called logical address. This address is the combnation of Net ID and Host ID. This address is used by network layer to identify a particular network (source to destination) among the networks. This address can be changed by changing the host position on the network. So it is called logical address.

BCA MCA BA MA BDP B.COM M.COM B.SC

http://www.ignouassignmentguru.com

to exchange SYN and ACK (acknowledgment) packets before actual data communication begins. A three-way handshake is also known as a TCP handshake. A three-way handshake is primarily used to create a TCP socket connection. It works when: A client node sends a SYN data packet over an IP network to a server on the same or an external network. The objective of this packet is to ask/infer if the server is open for new connections.  The target server must have open ports that can accept and initiate new connections. When the server receives the SYN packet from the client node, it responds and returns a confirmation receipt – the ACK packet or SYN/ACK packet.  The client node receives the SYN/ACK from the server and responds with an ACK packet. Upon completion of this process, the connection is created and the host and server can communicate.



Q.2. A.2.(a)

IGNOU ASSIGNMENT GURU Page-

5

TCP provides a connection oriented, reliable, byte stream service. The term connection-oriented means the two applications using TCP must establish a TCP connection with each other before they can exchange data. It is a full duplex protocol, meaning that each TCP connection supports a pair of byte streams, one flowing in each direction. TCP includes a flow-control mechanism for each of these byte streams that allows the receiver to limit how much data the sender can transmit. TCP also implements a congestion-control mechanism.

/IGNOUASSIGNMENTGURU

BCA MCA BA MA BDP B.COM M.COM B.SC

http://www.ignouassignmentguru.com

Two processes communicating via TCP sockets. Each side of a TCP connection has a socket which can be identified by the pair < IP_address, port_number >. Two processes communicating over TCP form a logical connection that is uniquely identifiable by the two sockets involved, that is by the combination < local_IP_address, local_port, remote_IP_address, remote_port>.

TCP provides the following facilities to: Stream Data Transfer From the application's viewpoint, TCP transfers a contiguous stream of bytes. TCP does this by grouping the bytes in TCP segments, which are passed to IP for transmission to the destination. TCP itself decides how to segment the data and it may forward the data at its own convenience.

Reliability TCP assigns a sequence number to each byte transmitted, and expects a positive acknowledgment (ACK) from the receiving TCP. If the ACK is not received within a timeout interval, the data is retransmitted. The receiving TCP uses the sequence numbers to rearrange the segments when they arrive out of order, and to eliminate duplicate segments.

Logical Connections The reliability and flow control mechanisms described above require that TCP initializes and maintains certain status information for each data stream. The combination of this status, including sockets, sequence numbers and window sizes, is called a logical connection. Each connection is uniquely identified by the pair of sockets used by the sending and receiving processes. Full Duplex TCP provides for concurrent data streams in both directions.

/IGNOUASSIGNMENTGURU

IGNOU ASSIGNMENT GURU Page-

Multiplexing To allow for many processes within a single host to use TCP communication facilities simultaneously, the TCP provides a set of addresses or ports within each host. Concatenated with the network and host addresses from the internet communication layer, this forms a socket. A pair of sockets uniquely identifies each connection.

6

Flow Control The receiving TCP, when sending an ACK back to the sender, also indicates to the sender the number of bytes it can receive beyond the last received TCP segment, without causing overrun and overflow in its internal buffers. This is sent in the ACK in the form of the highest sequence number it can receive without problems.

BCA MCA BA MA BDP B.COM M.COM B.SC

http://www.ignouassignmentguru.com

A.2.(b) Server Code /****************** SERVER CODE ****************/ #include #include #include #include

int main(){ int welcomeSocket, newSocket; char buffer[1024]; struct sockaddr_in serverAddr; struct sockaddr_storage serverStorage; socklen_t addr_size;

/*---- Create the socket. The three arguments are: ----*/ /* 1) Internet domain 2) Stream socket 3) Default protocol (TCP in this case) */

/*---- Configure settings of the server address struct ----*/ /* Address family = Internet */ serverAddr.sin_family = AF_INET; /* Set port number, using htons function to use proper byte order */ serverAddr.sin_port = htons(7891); /* Set IP address to localhost */ serverAddr.sin_addr.s_addr = inet_addr("127.0.0.1"); /* Set all bits of the padding field to 0 */

/IGNOUASSIGNMENTGURU

IGNOU ASSIGNMENT GURU Page-

7

welcomeSocket = socket(PF_INET, SOCK_STREAM, 0);

BCA MCA BA MA BDP B.COM M.COM B.SC

http://www.ignouassignmentguru.com

memset(serverAddr.sin_zero, '\0', sizeof serverAddr.sin_zero);

/*---- Bind the address struct to the socket ----*/ bind(welcomeSocket, (struct sockaddr *) &serverAddr, sizeof(serverAddr));

/*---- Listen on the socket, with 5 max connection requests queued ----*/ if(listen(welcomeSocket,5)==0) printf("Listening\n"); else printf("Error\n");

/*---- Accept call creates a new socket for the incoming connection ----*/ addr_size = sizeof serverStorage; newSocket = accept(welcomeSocket, (struct sockaddr *) &serverStorage, &addr_size);

/*---- Send message to the socket of the incoming connection ----*/ strcpy(buffer,"Hello World\n"); send(newSocket,buffer,13,0);

return 0;

Client Code /****************** CLIENT CODE ****************/ #include #include #include

/IGNOUASSIGNMENTGURU

IGNOU ASSIGNMENT GURU Page-

8

}

BCA MCA BA MA BDP B.COM M.COM B.SC

http://www.ignouassignmentguru.com

#include

int main(){ int clientSocket; char buffer[1024]; struct sockaddr_in serverAddr; socklen_t addr_size;

/*---- Create the socket. The three arguments are: ----*/ /* 1) Internet domain 2) Stream socket 3) Default protocol (TCP in this case) */ clientSocket = socket(PF_INET, SOCK_STREAM, 0);

/*---- Configure settings of the server address struct ----*/ /* Address family = Internet */ serverAddr.sin_family = AF_INET; /* Set port number, using htons function to use proper byte order */ serverAddr.sin_port = htons(7891); /* Set IP address to localhost */ serverAddr.sin_addr.s_addr = inet_addr("127.0.0.1"); /* Set all bits of the padding field to 0 */

/*---- Connect the socket to the server using the address struct ----*/ addr_size = sizeof serverAddr; connect(clientSocket, (struct sockaddr *) &serverAddr, addr_size);

/*---- Read the message from the server into the buffer ----*/ recv(clientSocket, buffer, 1024, 0);

/*---- Print the received message ----*/

/IGNOUASSIGNMENTGURU

IGNOU ASSIGNMENT GURU Page-

9

memset(serverAddr.sin_zero, '\0', sizeof serverAddr.sin_zero);

BCA MCA BA MA BDP B.COM M.COM B.SC

http://www.ignouassignmentguru.com

printf("Data received: %s",buffer);

return 0; }

A Simple Stream Client Program Example This client will connect to the host that you specify in the command line, with port 3490. It will get the string that the previous server sends. The following is the source code. /*** clientprog.c ****/ /*** a stream socket client demo ***/ 

#include #include #include #include #include #include #include #include #include

// the port client will be connecting to #define PORT 3490 // max number of bytes we can get at once

int main(int argc, char *argv[]) { int sockfd, numbytes; char buf[MAXDATASIZE]; struct hostent *he; // connector’s address information struct sockaddr_in their_addr;

/IGNOUASSIGNMENTGURU

IGNOU ASSIGNMENT GURU Page-

10

#define MAXDATASIZE 300

BCA MCA BA MA BDP B.COM M.COM B.SC

http://www.ignouassignmentguru.com

// if no command line argument supplied if(argc != 2) { fprintf(stderr, "Client-Usage: %s the_client_hostname\n", argv[0]); // just exit exit(1); }

// get the host info if((he=gethostbyname(argv[1])) == NULL) { perror("gethostbyname()"); exit(1); } else printf("Client-The remote host is: %s\n", argv[1]);

if((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {

11

perror("socket()");

IGNOU ASSIGNMENT GURU Page-

exit(1); }

/IGNOUASSIGNMENTGURU

BCA MCA BA MA BDP B.COM M.COM B.SC

http://www.ignouassignmentguru.com

else printf("Client-The socket() sockfd is OK...\n"); // host byte order their_addr.sin_family = AF_INET; // short, network byte order printf("Server-Using %s and port %d...\n", argv[1], PORT); their_addr.sin_port = htons(PORT); their_addr.sin_addr = *((struct in_addr *)he->h_addr); // zero the rest of the struct memset(&(their_addr.sin_zero), '\0', 8); if(connect(sockfd, (struct sockaddr *)&their_addr, sizeof(struct sockaddr)) == -1) { perror("connect()"); exit(1); } else printf("Client-The connect() is OK...\n"); if((numbytes = recv(sockfd, buf, MAXDATASIZE-1, 0)) == -1) { perror("recv()"); exit(1); } else printf("Client-The recv() is OK...\n"); buf[numbytes] = '\0'; printf("Client-Received: %s", buf);

Socket System Call In the early 1980s, with ARPA project, University of California at Berkeley had the responsibility to transport the TCP/IP protocol suit to Unix operating system. It was decided to use Unix system calls with addition to new system calls, if required, as the result new socket interface developed, which become popular as Berkeley UNX or BSD version 4.1. We are going to discuss BSD Unix system calls with you in this section. The socket system calls is used by any process to create a socket for doing any network 1/0. The structure of socket, we have already discussed as

/IGNOUASSIGNMENTGURU

IGNOU ASSIGNMENT GURU Page-

Q.3. A.3.(a)

12

printf("Client-Closing sockfd\n"); close(sockfd); return 0; }

BCA MCA BA MA BDP B.COM M.COM B.SC

/IGNOUASSIGNMENTGURU

IGNOU ASSIGNMENT GURU Page-

general but here we will discuss in detail with programming concept. The structure of this is given below. #include

#include int socket (into family, int type, int protocol ); Condition Returns Successfully Small integer value called the socket descriptor Unsuccessful Error (-1) Socket function creates a socket it sets values for only family, type and protocol of socket structure the other fields are set by other functions or by operating system. #include: This header file contains definitions of a number of data types used in system ca!Is. #include: The header file socket.h includes a number of definitions of structures needed for sockets. Socket Descriptor: As you know, in Unix, if some application needs to perform input/output function, it calls the "open" function to create the file descriptor which has further access to the file. Unix uses descriptor as an index ipto process descriptor table, which follows the pointers to the data structure that holds all details about file. Socket family: As you know socket family defines the protocol group needed for communication. At the time of programming you should choose one of the given options but because we are concerned about TCP/IP you need to remember AF-INST. Socket types: The Type parameter in socket system call specifies the semantics of communication. Sockets are typed according to the communication properties visible to a user. Mostly Processes can communicate only between sockets of the similar type. If underlying communication protocols support, communication between different types of sockets can happen. Protocol: The protocol specifies a particular protocol to be used with the socket. Normally only a single protocol exists to support a particular socket type within a given protocol family. Protocol is dependent on the services we are using in our communication. Data Transfer Calls Once a connection is established between sockets, an application program can send and receive data. Sending and receiving data can be done with any one of the several system calls given in this section. The system calls vary according to the amount of data to be transmitted and received and the state of the socket being used to perform the data transfers. The system iyall pairs (read, write), (send, recv), (sendto, recvfrom) can be used to transfer data (or communicate) on sockets. The sendto() subroutine allows the process to specify the destination for a message explicitly. read() : This is used to receive data from the remote machine, it assumes that there is already an open connection present between two machines and it is possible only in case of TCP (the connection oriented protocol in TCP/IP). Here in the above syntax of read() first sockfd is socket descriptor, buff is a

13

http://www.ignouassignmentguru.com

BCA MCA BA MA BDP B.COM M.COM B.SC

http://www.ignouassignmentguru.com

pointer to the buffer where we can store the data and buff len is length of buffer or capacity of buffer.

A.3.(b)

Connection Oriented and Connectionless Services These are the two services given by the layers to layers above them. These se...


Similar Free PDFs