ECE453 – Introduction to Computer Networks Lecture 15 – Transport Layer (II)

Slides:



Advertisements
Similar presentations
Sockets: Network IPC Internet Socket UNIX Domain Socket.
Advertisements

Today’s topic: Basic TCP API –Socket –Bind –Listen –Connect –Accept –Read –Write –Close.
Socket Programming Application Programming Interface.
Elementary TCP Sockets Computer Networks Computer Networks Term B10 UNIX Network Programming Vol. 1, Second Ed. Stevens Chapter 4.
Networks: TCP/IP Socket Calls1 Elementary TCP Sockets Chapter 4 UNIX Network Programming Vol. 1, Second Ed. Stevens.
Elementary TCP Sockets Chapter 4 UNIX Network Programming Vol. 1, Second Ed. Stevens.
Quick Overview. 2 ISO/OSI Reference Model Application Application Presentation Presentation Session Session Transport Transport Network Network Data Link.
תקשורת באינטרנט Tutorial 8. 2 n Socket programming u What is socket ? u Sockets architecture u Types of Sockets u The Socket system calls u Data Transfer.
Sockets Programming Introduction © Dr. Ayman Abdel-Hamid, CS4254 Spring CS4254 Computer Network Architecture and Programming Dr. Ayman A. Abdel-Hamid.
Tutorial 8 Socket Programming
#include DatatypeDescription int8_t uint8_t int16_t uint16_t int32_t uint32_t Signed 8-bit integer Unsigned 8-bit integer Signed 16-bit integer Unsigned.
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.
Socket Addresses. Domains Internet domains –familiar with these Unix domains –for processes communicating on the same hosts –not sure of widespread use.
Unix Network Programming Part 2: Elementary Sockets Jani Peusaari.
Lecture 10 Overview. Network API Application Programming Interface – Services that provide the interface between application and protocol software often.
1 Tutorial on Socket Programming Computer Networks - CSC 458 Department of Computer Science Yukun Zhu (Slides are mainly from Monia Ghobadi, and Amin Tootoonchian,
Basic Socket Programming TCP/IP overview. TCP interface Reference: –UNIX Network Programming, by Richard Stevens. –UNIX man page.
TCP Socket Programming. r An abstract interface provided to the application programmer  File descriptor, allows apps to read/write to the network r Allows.
ECE 4110 – Internetwork Programming Client-Server Model.
TCP/IP Protocol Stack IP Device Drivers TCPUDP Application Sockets (Gate to network) TCP: –Establish connection –Maintain connection during the communication.
Network Programming Tutorial #9 CPSC 261. A socket is one end of a virtual communication channel Provides network connectivity to any other socket anywhere.
Client-Side Network Programming
CS345 Operating Systems Φροντιστήριο Άσκησης 2. Inter-process communication Exchange data among processes Methods –Signal –Pipe –Sockets.
Introduction to Socket Programming Advisor: Quincy Wu Speaker: Kuan-Ta Lu Date: Nov. 25, 2010.
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.
Ports Port - A 16-bit number that identifies the application process that receives an incoming message. Reserved ports or well-known ports (0 to 1023)
Networking Tutorial Special Interest Group for Software Engineering Luke Rajlich.
TELE202 Lecture 15 Socket programming 1 Lecturer Dr Z. Huang Overview ¥Last Lecture »TCP/UDP (2) »Source: chapter 17 ¥This Lecture »Socket programming.
Lecture 15 Overview.
CSCE 515: Computer Network Programming UDP Socket Wenyuan Xu Department of Computer Science and Engineering.
Elementary TCP Sockets UNIX Network Programming Vol. 1, Second Ed. Stevens Chapter 4.
Introduction to Socket
Socket Programming Lab 1 1CS Computer Networks.
1 Sockets Programming Socket to me!. 2 Network Application Programming Interface (API) The services provided by the operating system that provide the.
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,
1 CS716 Advanced Computer Networks By A. Wahid Shaikh.
Sockets Introduction Socket address structures Value-result arguments
Introduction to Sockets
Read() recv() connection establishment Server (connection-oriented protocol) blocks until connection from client Client socket() bind() listen() accept()
2: Application Layer 1 Socket Programming UNIX Network Programming, Socket Programming Tutorial:
CSCI 330 UNIX and Network Programming Unit XIV: User Datagram Protocol.
1 Spring Semester 2008, Dept. of Computer Science, Technion Internet Networking recitation #7 Socket Programming.
Advanced UNIX programming Fall 2002 Instructor: Ashok Srinivasan Lecture 17 Acknowledgements: The syllabus and power point presentations are modified versions.
Lecture 15 Socket Programming CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger.
Lecture 3 TCP and UDP Sockets CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger.
Socket Programming Jignesh Patel Palanivel Rathinam connecting processes.
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.
Onward with Chat! Networking CS 3470, Section 1.
Network Programming CSC- 341
Socket Programming (Cont.)
Network Programming CSC- 341
Network and Sockets Today: Get started doing network programming
Socket Programming in C
Socket Interface 1 Introduction 11 Socket address formats 2 API 12 13
Transport layer API: Socket Programming
Chapter 3 Sockets Introduction
CSE454 Internet Technology. Asst. Prof. Dr
Introduction to Socket Programming
Socket Programming in C
TCP/IP Socket Programming in C
Socket Programming(1/2)
Sockets Programming Socket to me!.
Sockets Programming Socket to me!.
Internet Networking recitation #8
Outline Communications in Distributed Systems Socket Programming
Today’s topic: Basic TCP API
Presentation transcript:

ECE453 – Introduction to Computer Networks Lecture 15 – Transport Layer (II)

Transport Services Connection-oriented Service TCP Reliable data transfer TCP flow control TCP congestion control TCP connection management Connectionless Service UDP Through socket programming

Socket Programming process TCP with buffers, variables socket host or server process TCP with buffers, variables socket host or server internet

TCP Socket Programming Flow Server Client socket() listen() accept() read() bind() Block until connection from client Process requests write() read() close() socket() write() connect() read() close() well-known port Connection establishment TCP three-way handshake Data (request) Data (reply) End-of-file notification Implicit bind

UDP Socket Programming Flow Server socket( ) recvfrom ( ) bind ( ) Client socket ( ) sendto ( )

Socket APIs result = socket(pf, type, protocol) close(socket) bind(socket, localaddr, addrlen)

Create A Socket Pf : protocol family, example, PF_INET (TCP/IP), PF_UNIX (IPC, local) Type: specify the type of communication (service model) desired, example, SOCKET_STREAM (TCP), SOCKET_DGRAM (UDP), SOCKET_RAW (bypass TCP/UDP, use IP directly) Protocol: select a specific protocol within the family. It is needed when there are more than one protocol to support the type of service desired. Usually is 0 result = socket(pf, type, protocol)

Close A Socket Socket: specify the descriptor of socket to be closed Internally, a call to close() decrements the reference count for a socket and destroys the socket if the count reaches zero Socket can be used by multiple applications close(socket)

Specify Local Address localaddr: a structure that specifies the local address to which the socket should be bound addrlen: an integer that specifies the length of address measured in bytes bind(socket, localaddr, addrlen)

Structure of Local Address Address family (2)Protocol port IP address (in_addr) unused struct sockaddr_in { short sin_family; /* must be AF_INET */ u_short sin_port; /* protocol port, can ignore */ struct in_addr sin_addr; /* IP address */ char sin_zero[8]; /* Not used, must be zero */ }; struct in_addr { in_addr_t s_addr; /* 32 bit ipv4 address, network byte ordered */ };

Connect Sockets to Destination destaddr: a socket address structure that specifies the destination address to which a socket should be bound. connect(socket, destaddr, addrlen)

Specify A Queue Length for A Server listen() allows server to prepare a socket for incoming connections, and it puts the socket in a passive mode ready to accept connections It also tells server to en-queue up to “qlength” requests for connections, when full, discard new requests listen() only applies to sockets that have selected reliable data delivery services listen(socket, qlength)

Accepts Connections A call to accept() blocks until a connection requests arrives When the request arrives, the system fills in argument “addr” with the address of the client that has placed the request, and “addrlen” to the length of the address Return a new socket with its destination connected to the requesting client The original socket still has a wild card foreign destination address, and it still remains open newsock=accept(socket,addr,addrlen)

Accepts Connection: Illustration Client A Server Process Original socket Newly returned socket #1 Client B #2 Newly returned socket Original socket pipe accept

Send Data Through Socket write(socket,buffer,length) writev(socket,iovector,vectorlen) send(socket,message,length,flags) sendto(socket,message,length,flags, Destaddr, addrlen) sendmsg(socket,messagestruct,flags)

Receive Data Through Socket read(socket,buffer,length) readv(socket,iovector,vectorlen) recv(socket,message,length,flags) recvfrom(socket,message,length, flags,Destaddr, addrlen) recvmsg(socket,messagestruct,flags)

Byte Ordering High-order byteLow-order byte MSB 16-bit value LSB Low-order byteHigh-order byte Increasing memory address Address AAddress A+1 Little-endian byte order Big-endian byte order Address A+1Address A

Implications of Byte Order Unfortunately there is no standard between these two byte orderings and we encounter systems that use both formats We refer to the byte ordering used by a given system as host byte order The sender and the receiver must agree on the order in which the bytes of these multi- byte field transmitted: specify network byte order, which is big-endian byte ordering

Byte Order Functions #include uint16_t htons(uint16_t host16bitvalue) Converts a 16-bit integer from host to network byte order uint32_t htonl(uint32_t host32bitvalue) Converts a 32-bit integer from host to network byte order Both return: value in network byte order uint16_t ntohs(uint16_t net16bitvalue) uint32_t ntohl(uint32_t net32bitvalue) Both return: value in host byte order

Byte Manipulation Functions #include /* Berkeley-derived functions */ void bzero(void *dest, size_t nbytes) Set the first part of an object to null bytes void bcopy(const void *src, void *dest, size_t nbytes); int bcmp(const void *ptr1, const void *ptr2, size_t nbytes) /* return:0 if equal, nonzero if unequal */ #include /* ANSI C defined functions */ void *memset(void *dest,int c,size_t len) Sets the first len bytes in memory dest to the value of c void *memcpy(void *dest,const void *src, size_t nbytes) void memcmp(const void *ptr1, const void *ptr2, size_t nbytes)

Address Conversion Functions #include int inet_aton(const char *strptr, struct in_addr *addrptr); /* return 1 if string was valid,0 error */ Convert an IP address in string format (x.x.x.x) to the 32-bit packed binary format used in low-level network functions in_addr_t inet_addr(const char *strptr); /* return 32-bit binary network byte ordered IPv4 address; INADDR_NONE if error, deprecated and replaced by inet_aton() */ char *inet_ntoa(struct in_addr inaddr); /* returns: pointer to dotted-decimal string */

/* A simple server in the internet domain using TCP */ #include int main(int argc, char *argv[]) { int sockfd, newsockfd, portno, clilen; char buffer[256]; struct sockaddr_in serv_addr, cli_addr; int n; … sockfd = socket(PF_INET, SOCK_STREAM, 0); bzero((char *) &serv_addr,sizeof(serv_addr)); portno = atoi(argv[1]); serv_addr.sin_family = AF_INET; serv_addr.sin_addr.s_addr = INADDR_ANY; serv_addr.sin_port = htons(portno); if (bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) error("ERROR on binding"); listen(sockfd,5); clilen = sizeof(cli_addr); newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, &clilen); bzero(buffer,256); n = read(newsockfd,buffer,255); printf("Here is the message: %s\n",buffer); n = write(newsockfd,"I got your msg",18); return 0; }

/* Client program */ #include int main(int argc, char *argv[]) { int sockfd, portno, n; struct sockaddr_in serv_addr; struct hostent *server; char buffer[256]; portno = atoi(argv[2]); sockfd = socket(PF_INET, SOCK_STREAM, 0); server = gethostbyname(argv[1]); bzero((char *) &serv_addr, sizeof(serv_addr)); serv_addr.sin_family = AF_INET; bcopy((char *)server->h_addr, (char *)&serv_addr.sin_addr.s_addr, server->h_length); serv_addr.sin_port = htons(portno); if (connect(sockfd,&serv_addr, sizeof(serv_addr)) < 0) error("ERROR connecting"); printf("Please enter the message: "); bzero(buffer,256); fgets(buffer,255,stdin); n = write(sockfd,buffer,strlen(buffer)); bzero(buffer,256); n = read(sockfd,buffer,255); printf("%s\n",buffer); return 0; }