Lecture Notes on Transport Layer

Lecture Notes on Transport Layer - Chapter 6 Transport...

Info icon This preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Chapter 6 Transport Layer Transport layer Provides end-to-end data transport for user. Depends upon services of network layer. Required because network layer is not generally reliable and often controlled by someone other than network user. The TPDU (Transport Protocol Data Unit) discussed in the text corresponds to the TCP (Transmission Control Protocol) header and data load. The TPDU is contained within a network packet which is itself contained within a data link frame as illustrated below for Ethernet, IP, and TCP protocols: 6.1.3 Berkley Sockets - A standard set of transport primitives used in Berkley UNIX for TCP and widely ported to other systems, including Windows, though Microsoft made significant improvements such as changing the spelling of several functions. TCP Socket Primitives Primitive Meaning SOCKET Create new communication end point in program BIND Attach a local port address to a socket LISTEN Open socket to connection requests and define number of queued connections ACCEPT Block execution until a connection request arrives; server CONNECTAttempt to establish connection (e.g. to a program blocked at an ACCEPT); client SEND Send data over a connection (encapsulated within an TCP segment) RECEIVE Receive data over a connection. CLOSE Opposite of ACCEPT and CONNECT The following example of an echo client/server illustrates the relative ease that networked applications can be implemented using the Berkley sockets. For a complete version see TCP Client and TCP Server . Most languages implement network operations ad hoc using function libraries, newer languages such as Java are designed to include networking as part of the language. Echo Server and Client using Berkley Socket Primitives
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
// Server #include <winsock2.h> void main(void) { char buffer[128]; int retval, sinlen; struct sockaddr_in sin; SOCKET s, h; WSAStartup(0x202,&wsaData); sin.sin_family = AF_INET; sin.sin_addr.s_addr = INADDR_ANY; sin.sin_port = htons(888); // Port 888 // SOCK_STREAM is TCP s = socket (AF_INET, SOCK_STREAM,0); // Bind socket to local port bind (s,(struct sockaddr*)&sin,sizeof(sin)); // Listen for 1 connection listen (s,1); sinlen = sizeof(sin); // 1. Block for connection request h= accept (s,(struct sockaddr*)&sin,&sinlen ); // 2. Block for receive recv (h,buffer,sizeof(buffer),0); // 3. Echo what is received send (h,buffer,strlen(buffer),0); closesocket (h); } // Client #include <winsock2.h> #include <iostream.h> void main(int argc, char* argv[]) { char buffer[128]= "Hello"; int retval; unsigned int addr=0; struct sockaddr_in sin; struct hostent *host; SOCKET s; WSAStartup(0x202,&wsaData); // Assume valid DNS given host = gethostbyname(argv[1]); memcpy(&(sin.sin_addr), host->h_addr,host->h_length); sin.sin_family = host->h_addrtype; sin.sin_port = htons(888); // Create socket port 888 s = socket (AF_INET, SOCK_STREAM,0); // 1. Block for server accept connection connect (s, (struct sockaddr*)&sin,sizeof(sin)); // 2. Send "Hello" send (s,buffer,strlen(buffer)+1,0); // 3. Block for Receive recv (s,buffer,sizeof(buffer),0); // Print what is received cout << "Received " << buffer << "\n"; closesocket (s); } Python Echo Server and Client using Berkley Socket Primitives // Server import socket // Client import socket
Image of page 2
s = socket.
Image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern