2: Application Layer1 Chapter 2: Application layer r 2.1 Principles of network applications r 2.2 Web and HTTP r 2.3 FTP r 2.4 Electronic Mail  SMTP,

Slides:



Advertisements
Similar presentations
Introduction to Sockets Jan Why do we need sockets? Provides an abstraction for interprocess communication.
Advertisements

Socket Programming in C Slides Adapted on Jörn Altmann‘s Slides.
Introduction to Information Security Networking. Transmission Control Protocol (aka TCP) Most widely used protocol A TCP Connection is based on 6 crucial.
Application Layer 2-1 Chapter 2 Application Layer Computer Networking: A Top Down Approach 6 th edition Jim Kurose, Keith Ross Addison-Wesley March 2012.
Networks: TCP/IP Socket Calls1 Elementary TCP Sockets Chapter 4 UNIX Network Programming Vol. 1, Second Ed. Stevens.
2: Application Layer 1 Socket programming Socket API r introduced in BSD4.1 UNIX, 1981 r explicitly created, used, released by apps r client/server paradigm.
Quick Overview. 2 ISO/OSI Reference Model Application Application Presentation Presentation Session Session Transport Transport Network Network Data Link.
Socket Programming.
Socket Programming: a Primer Socket to me!. Feb. 23, 2001EE122, UCB2 Why does one need sockets? application network protocol sockets network.
Tutorial 8 Socket Programming
1 Overview r Socket programming with TCP r Socket programming with UDP r Building a Web server.
UDP: User Datagram Protocol. UDP: User Datagram Protocol [RFC 768] r “bare bones”, “best effort” transport protocol r connectionless: m no handshaking.
CS 311 – Lecture 18 Outline IPC via Sockets – Server side socket() bind() accept() listen() – Client side connect() Lecture 181CS Operating Systems.
CSE/EE 461 Getting Started with Networking. Basic Concepts  A PROCESS is an executing program somewhere.  Eg, “./a.out”  A MESSAGE contains information.
1 School of Computing Science Simon Fraser University CMPT 771/471: Internet Architecture and Protocols Socket Programming Instructor: Dr. Mohamed Hefeeda.
TCP Socket Programming. r An abstract interface provided to the application programmer  File descriptor, allows apps to read/write to the network r Allows.
EECC694 - Shaaban #1 lec #14 Spring The Application Layer Client/Server Computing, Basic Approaches: –Passing Messages. Example: Communication.
2: Application Layer 1 Chapter 2 Application Layer Computer Networking: A Top Down Approach, 5th edition. Jim Kurose, Keith Ross Addison-Wesley, April.
Introduction to Project 1 Web Client and Server Jan 2006.
Introduction to Information Security Networking. Transmission Control Protocol (aka TCP) Most widely used protocol A ‘reliable’ (but not secure!) protocol.
TCP Socket Programming. r An abstract interface provided to the application programmer  File descriptor, allows apps to read/write to the network r Allows.
Socket programming in C. Socket programming Socket API introduced in BSD4.1 UNIX, 1981 explicitly created, used, released by apps client/server paradigm.
CS1652 September 13th, 2012 The slides are adapted from the publisher’s material All material copyright J.F Kurose and K.W. Ross, All Rights.
Sockets and intro to IO multiplexing. Goals We are going to study sockets programming as means to introduce IO multiplexing problem. We will revisit socket.
2: Application Layer1 Chapter 2: Application layer r 2.1 Principles of network applications r 2.2 Web and HTTP r 2.3 FTP r 2.4 Electronic Mail  SMTP,
2: Application Layer1 Socket programming Socket API r introduced in BSD4.1 UNIX, 1981 r explicitly created, used, released by apps r client/server paradigm.
2: Application Layer 1 Chapter 2: Application layer r 2.1 Principles of network applications r 2.2 Web and HTTP r Internet gaming r 2.3 FTP r 2.4 Electronic.
Sirak Kaewjamnong Computer Network Systems
Server Sockets: A server socket listens on a given port Many different clients may be connecting to that port Ideally, you would like a separate file descriptor.
The Application Layer Application Services (Telnet, FTP, , WWW) Reliable Stream Transport (TCP) Connectionless Packet Delivery Service (IP) Unreliable.
 Wind River Systems, Inc Chapter - 13 Network Programming.
2: Application Layer1 Chapter 2 Application Layer Computer Networking: A Top Down Approach 6 th edition Jim Kurose, Keith Ross Addison-Wesley March 2012.
Application Layer 2-1 Chapter 2 Application Layer Computer Networking: A Top Down Approach 6 th edition Jim Kurose, Keith Ross Addison-Wesley March 2012.
Application Layer 2-1 Chapter 2 Application Layer Computer Networking: A Top Down Approach 6 th edition Jim Kurose, Keith Ross Addison-Wesley March 2012.
Computer Network Sritrusta Sukaridhoto. Why Computer Network ??? Stand alone Computer …. FOR WHAT ???
2: Application Layer1 Chapter 2: Application layer r 2.1 Principles of network applications r 2.2 Web and HTTP r 2.3 FTP r 2.4 Electronic Mail  SMTP,
Networking Tutorial Special Interest Group for Software Engineering Luke Rajlich.
1 Computer Networks An Introduction to Computer Networks University of Tehran Dept. of EE and Computer Engineering By: Dr. Nasser Yazdani Lecture 3: Sockets.
TELE202 Lecture 15 Socket programming 1 Lecturer Dr Z. Huang Overview ¥Last Lecture »TCP/UDP (2) »Source: chapter 17 ¥This Lecture »Socket programming.
Introduction to Socket
CSE/EE 461 Getting Started with Networking. 2 Basic Concepts A PROCESS is an executing program somewhere. –Eg, “./a.out” A MESSAGE contains information.
2: Application Layer 1 Chapter 2: Application layer r 2.1 Principles of network applications r 2.2 Web and HTTP r Internet gaming r 2.3 FTP r 2.4 Electronic.
Sockets Socket = abstraction of the port concept: –Application programs request that the operating system create a socket when one is needed –O.S. returns.
CSCI 330 UNIX and Network Programming Unit XV: Transmission Control Protocol.
S OCKET P ROGRAMMING IN C Professor: Dr. Shu-Ching Chen TA: HsinYu Ha.
S OCKET P ROGRAMMING IN C Professor: Dr. Shu-Ching Chen TA: Hsin-Yu Ha.
2: Application Layer 1 Socket Programming UNIX Network Programming, Socket Programming Tutorial:
CSCI 330 UNIX and Network Programming Unit XIV: User Datagram Protocol.
Application Layer 2-1 Chapter 2 Application Layer Computer Networking: A Top Down Approach 6 th edition Jim Kurose, Keith Ross Application Layer – Lecture.
1 Spring Semester 2008, Dept. of Computer Science, Technion Internet Networking recitation #7 Socket Programming.
Socket programming in C. Socket programming Socket API introduced in BSD4.1 UNIX, 1981 explicitly created, used, released by apps client/server paradigm.
Socket programming in C. Socket programming with TCP Client must contact server server process must first be running server must have created socket (door)
Socket Programming in C CS587x Lecture 3 Department of Computer Science Iowa State University.
1 Socket Interface. 2 Client-Server Architecture The client is the one who speaks first Typical client-server situations  Client and server on the same.
Socket Programming(1/2). Outline  1. Introduction to Network Programming  2. Network Architecture – Client/Server Model  3. TCP Socket Programming.
1 Socket Interface. 2 Basic Sockets API Review Socket Library TCPUDP IP EthernetPPP ARP DHCP, Mail, WWW, TELNET, FTP... Network cardCom Layer 4 / Transport.
SOCKET PROGRAMMING Presented By : Divya Sharma.
Sockets and Beginning Network Programming
CS 1652 Jack Lange University of Pittsburgh
Introduction to Information Security
Socket Programming in C
Socket Interface 1 Introduction 11 Socket address formats 2 API 12 13
Chapter 2 Application Layer
Transport layer API: Socket Programming
Chapter 2: Application layer
Chapter 2: Application layer
Chapter 2 Application Layer
Internet Networking recitation #8
Chapter 2: Application layer
Presentation transcript:

2: Application Layer1 Chapter 2: Application layer r 2.1 Principles of network applications r 2.2 Web and HTTP r 2.3 FTP r 2.4 Electronic Mail  SMTP, POP3, IMAP r 2.5 DNS r 2.6 P2P file sharing r 2.7 Socket programming with TCP r 2.8 Socket programming with UDP r 2.9 Building a Web server

2: Application Layer2 Socket programming Socket API r introduced in BSD4.1 UNIX, 1981 r explicitly created, used, released by apps r client/server paradigm r two types of transport service via socket API:  unreliable datagram (UDP)  reliable, byte stream-oriented (TCP) Goal: learn how to build client/server application that communicate using sockets

2: Application Layer3 Socket-programming using TCP Socket: an interface between application process and end-end-transport protocol (UCP or TCP) Why socket?: A Layer seen by application, OS transparent process TCP with buffers, variables socket controlled by application developer controlled by operating system host or server process TCP with buffers, variables socket host or server internet

2: Application Layer4 Socket programming with TCP Client must contact server r server process must first be running r server must have created socket (door) that accepts client’s contact Client contacts server by: r creating client-local TCP socket r specifying IP address, port number of server process r When client creates socket: client TCP establishes connection to server TCP r When contacted by client, server TCP creates new socket for server process to communicate with client  allows server to talk with multiple clients  source port numbers used to distinguish clients (more in Chap 3) TCP provides reliable, in-order transfer of bytes (“pipe”) between client and server application viewpoint

2: Application Layer5 Many Versions of Socket APIs r Unix socket (berkeley socket) r Winsock r MacTCP r …. r We introduce Unix socket API here  Can program under SUN OS, Linux, etc

2: Application Layer6 Unix Descriptor Table Descriptor Table Data structure for file 0 Data structure for file 1 Data structure for file 2

2: Application Layer7 Socket Descriptor Data Structure Descriptor Table Family: AF_INET Service: SOCK_STREAM Local IP: Remote IP: Local Port: 2249 Remote Port: 3726 Family: AF_INET Service: SOCK_STREAM Local IP: Remote IP: Local Port: 2249 Remote Port: 3726

2: Application Layer8 TCP Client/Server Socket Overview socket() bind() listen() accept() send() recv() close() socket() TCP Client connect() send() recv() close() connection establishment data request data reply end-of-file notification TCP Server bind()

2: Application Layer9 What is a Socket? r socket returns an integer (socket descriptor)  sockfd < 0 indicates that an error occurred  socket descriptors are similar to file descriptors r AF_INET: associates a socket with the Internet protocol family r SOCK_STREAM: selects the TCP protocol r SOCK_DGRAM: selects the UDP protocol int sockfd; /* socket descriptor */ if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) } perror(“socket”); exit(1); }

2: Application Layer10 Socket Structure and Bind (Client) struct sockaddr_in { short int sin_family; // Address family unsigned short int sin_port; // Port number struct in_addr sin_addr; // Internet address unsigned char sin_zero[8]; // all zero }; AF_INET int sockfd; struct sockaddr_in local_addr; local_addr.sin_family = AF_INET; local_addr.sin_port = 0; // random assign a port local_addr.sin_addr.s_addr = INADDR_ANY; // use my IP address memset(&(my_addr.sin_zero), '\0', 8); // zero the rest of the struct sockfd = socket(AF_INET, SOCK_STREAM, 0); // create an empty socket bind(sockfd, (struct sockaddr *)&local_addr, sizeof(struct sockaddr); Local host info

2: Application Layer11 Remote Host Structure hostent *hp; hp = gethostbyname(“mail.cs.ucf.edu”); “ ” struct hostent { char *h_name; /* official name */ char **h_aliases; /* alias list */ int h_addrtype; /* address type */ int h_length; /* address length */ char **h_addr_list; /* address list */ }; #define h_addr h_addr_list[0] Longwood.cs.ucf.edu struct sockaddr_in remote_addr; remote_addr.sin_family = AF_INET; remote_addr.sin_port = htons(80); // short, network byte order remote_addr.sin_addr = *((struct in_addr *)hp->h_addr); memset(&(remote_addr.sin_zero), '\0', 8); // zero the rest mail.cs.ucf.edu Remote host info

2: Application Layer12 Connect(), send(), recv() by Client connect(sockfd, (struct sockaddr *)&remote_addr, sizeof(struct sockaddr); Struct sockaddr  sockaddr_in After connecting to the remote sever…. char sendStr[100], recvStr[100]; …. send(sockfd, sendStr, strlen(sendStr), 0); … recvNumByte = recv(sockfd, recvStr, MaxDataSize, 0); close(sockfd); Blocking call Remote host info Local host socket

2: Application Layer13 Socket Programming in Server r No need to connect() a remote host r Need to listen() on specified port r Accept() a connection request  Generate a new socket for one connection Support multiple connections listen(sockfd, backLog); // backLog is the number of connections in queue new_fd = accept(sockfd, (struct sockaddr *)&remote_addr, &sizeof(struct sockaddr_in)) New socket discriptor Following commun. through this

2: Application Layer14 Socket Programming in Server: fork() for multi-connection service while(1) { // main accept() loop sin_size = sizeof(struct sockaddr_in); new_fd = accept(sockfd, (struct sockaddr *)&remote_addr, &sin_size); printf("server: got connection from %s\n", inet_ntoa(remote_addr.sin_addr)); if (!fork()) { // this is the child process close(sockfd); // child doesn't need the listener send(new_fd, "Hello, world!\n", 14, 0); close(new_fd); exit(0); } close(new_fd); // parent doesn't need this }

2: Application Layer15 Chapter 2: Application layer r 2.1 Principles of network applications r 2.2 Web and HTTP r 2.3 FTP r 2.4 Electronic Mail  SMTP, POP3, IMAP r 2.5 DNS r 2.6 P2P file sharing r 2.7 Socket programming with TCP r 2.8 Socket programming with UDP r 2.9 Building a Web server

2: Application Layer16 Socket programming with UDP UDP: no “connection” between client and server r no handshaking r sender explicitly attaches IP address and port of destination to each packet r server must extract IP address, port of sender from received packet UDP: transmitted data may be received out of order, or lost application viewpoint UDP provides unreliable transfer of groups of bytes (“datagrams”) between client and server

2: Application Layer17 UDP Socket Programming r sockfd = socket(AF_INET, SOCK_DGRAM, 0) r No connect(), accept() r Send()  sendto(), recv()  recvfrom()  Sendto() includes target address/port SOCK_STREAM (tcp)

2: Application Layer18 Chapter 2: Summary r Application architectures  client-server  P2P  hybrid r application service requirements:  reliability, bandwidth, delay r Internet transport service model  connection-oriented, reliable: TCP  unreliable, datagrams: UDP Our study of network apps now complete! r specific protocols:  HTTP  FTP  SMTP, POP, IMAP  DNS r socket programming

2: Application Layer19 Chapter 2: Summary r typical request/reply message exchange:  client requests info or service  server responds with data, status code r message formats:  headers: fields giving info about data  data: info being communicated Most importantly: learned about protocols r control vs. data msgs  in-band, out-of-band (ftp) r centralized vs. decentralized r stateless vs. stateful r reliable vs. unreliable msg transfer r “complexity at network edge”