NP-UNIT1_Introduction to Transport Layer
NP-UNIT1_Introduction to Transport Layer
NP-UNIT1_Introduction to Transport Layer
UNIT-1
•Introduction: Introduction, Client/server communication, OSI
Model, BSD Networking history, Test Networks and Hosts, Unix
Standards, 64-bit architectures.
• Transport Layer: TCP, UDP and SCTP, TCP Connection Establishment
and Termination.
• Self learning topics: TCP/IP Protocols in nut shell.
Network programming involves writing programs to
communicate with processes either on the same or on
other machines on the network using standard Protocols…
High-level decision must be made as to which program would initiate
the communication first and when responses are expected…
WebServer program waits for clients to send request and only after the
request is received it responds with a reply…
Single Server – Serving multiple Clients
https://www.youtube.com/watch?v=1z0ULvg_pW8
OSI - Model
TCP/IP Model
BSD
BSD
BSD History
BSD Network
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
Source Code of Day Time Client
#include <netdb.h>
#include <stdio.h>
return 0;
}
while ((n = read(sockfd, recvline, 1000)) > 0) {
recvline[n] = 0;
fputs(recvline, stdout);
}
return 0;
}
struct in_addr {
};
DayTime Server…
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdio.h>
char buff[1000];
time_t ticks;
CREATE A SOCKET
listenfd = socket(AF_INET, SOCK_STREAM, 0);
bzero(&servaddr, sizeof(servaddr));
Initialize Socket Address
servaddr.sin_family = AF_INET;
servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
servaddr.sin_port = htons(port);
bind(listenfd, (struct sockaddr *) &servaddr, sizeof(servaddr)); Bind the SOCKET
listen(listenfd, 8);
Listen on the Port for connections
for (;;) {
connfd = accept(listenfd, (struct sockaddr *) NULL, NULL); Accept connection request from Client
ticks = time(NULL);
close(connfd);
}
}
int main()
{ Source Code of Day Time Client – IPV6
int s;
struct sockaddr_in6 addr;
close(sockfd);
return 0;
}
}
We find that most of the time, this is what we want to do. Occasionally, we want to do
something other than terminate when one of these functions returns an error
{ int n;
if ( (n = socket(family, type, protocol)) < 0)
err_sys("socket error");
return (n);
}
}
1. The server must be prepared to accept an incoming connection. This is normally done
by calling socket, bind, and listen and is called a passive open.
2. The client issues an active open by calling connect. This causes the client TCP
to send a "synchronize" (SYN) segment, which tells the server the client's
initial sequence number for the data that the client will send on the connection.
Normally, there is no data sent with the SYN; it just contains an IP header, a
TCP header, and possible TCP options
3. The server must acknowledge (ACK) the client's SYN and the server must also send
its own SYN containing the initial sequence number for the data that the server will
send on the connection. The server sends its SYN and the ACK of the client's SYN in a
single segment.
• Window scale option. The maximum window that either TCP can
advertise to the other TCP is 65,535
2. The other end that receives the FIN performs the passive close. The received
FIN is acknowledged by TCP. The receipt of the FIN is also passed to the
application as an end-of-file (after any data that may have already been
queued for the application to receive), since the receipt of the FIN means the
application will not receive any additional data on the connection.
3. Sometime later, the application that received the end-of-file will close its
socket. This causes its TCP to send a FIN.
4. The TCP on the system that receives this final FIN (the end that did the active
close) acknowledges the FIN.
TCP State Transition Diagram
• The operation of TCP with regard to connection establishment and
connection termination can be specified with a state transition diagram.
• There are 11 different states defined for a connection and the rules of TCP
dictate the transitions from one state to another, based on the current
state and the segment received in that state.
• If TCP next receives a SYN with an ACK, it sends an ACK and the new state is
ESTABLISHED. This final state is where most data transfer occurs.
• The two arrows leading from the ESTABLISHED state deal with the
termination of a connection.
TCP - Connection
TCP – Connection : Packet Exchange
TCP-Connection state diagram
}
UDP
}
SCTP – Closing
}
SCTP – State Transition Diagram
}
SCTP – Packet Exchange
}