We will cover in this order: 2.1, 2.7, 2.5, 2.4, 2.2

Similar documents
Application Programming Interfaces

Computer Communication Networks Socket Programming

Chapter II: Application Layer

Chapter 2: outline. 2.1 principles of network applications. 2.6 P2P applications 2.7 socket programming with UDP and TCP

Chapter 2: outline. 2.6 P2P applications 2.7 socket programming with UDP and TCP

Client/Server Computing & Socket Programming

Distributed Systems. Remote Procedure Calls

Chapter 2 Application Layer

Distributed Systems. Networking Slides courtesy Kurose & Ross

Chapter 2: outline. 2.1 principles of network applications app architectures app requirements

Communication in Distributed Systems: Sockets Programming. Operating Systems

CMPE 150/L : Introduction to Computer Networks. Chen Qian Computer Engineering UCSC Baskin Engineering Lecture 6

The Application Layer: Sockets Wrap-Up

Quick Guide to Python Socket Programming 吳俊興 國立高雄大學資訊工程學系

ELEC / COMP 177 Fall Some slides from Kurose and Ross, Computer Networking, 5 th Edition

Chapter 2 Application Layer

CSCD 330 Network Programming Spring 2018

JAVA SOCKET PROGRAMMING

Application Layer. CMPS 4750/6750: Computer Networks

Chapter 2 outline. 2.1 Principles of app layer protocols

Chapter 2: Application Layer. Chapter 2: application layer. outline. Some network apps. Client-server architecture. Application architectures

CSC 401 Data and Computer Communications Networks

CS 3516: Advanced Computer Networks

Introduction to the Application Layer. Computer Networks Term B14

Client/Server Computing & Socket Programming

Chapter 2: Application Layer. Chapter 2 Application Layer. Some network apps. Application architectures. Chapter 2: Application layer

Interprocess Communication Mechanisms

shared storage These mechanisms have already been covered. examples: shared virtual memory message based signals

Computer Communication Networks Foundation

IEMS 5780 / IERG 4080 Building and Deploying Scalable Machine Learning Services

Network Programming with Python. Sébastien Tixeuil

Memory-Mapped Files. generic interface: vaddr mmap(file descriptor,fileoffset,length) munmap(vaddr,length)

Computer Networking Introduction

Transport Layer (TCP/UDP)

Chapter 2 Application Layer. Lecture 4: principles of network applications. Computer Networking: A Top Down Approach

CS 355. Computer Networking. Wei Lu, Ph.D., P.Eng.

Chapter 1 Introduction

Chapter 2. Application Layer. Chapter 2: Application Layer. Application layer - Overview. Some network apps. Creating a network appication

Web Caching and HTTPS

Chapter 2: outline. 2.5 P2P applications 2.6 video streaming and content distribution networks 2.7 socket programming with UDP and TCP

Esempi di programmi client/server in Python 2

Foundations of Telematics

CSE 461 Connections. David Wetherall

CSCD 330 Network Programming Winter 2019

CSCD 330 Network Programming Spring 2018

COMMUNICATION PROTOCOLS: REMOTE PROCEDURE CALL (RPC)

Chapter 2: outline. 2.5 P2P applications 2.6 video streaming and content distribution networks 2.7 socket programming with UDP and TCP

Network Programming in Python. Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island

CSE/EE 461 Lecture 14. Connections. Last Time. This Time. We began on the Transport layer. Focus How do we send information reliably?

CC451 Computer Networks

Review of Previous Lecture

Processes communicating. Network Communication. Sockets. Addressing processes 4/15/2013

ELEC / COMP 177 Fall Some slides from Kurose and Ross, Computer Networking, 5 th Edition

Different Layers Lecture 21

Socket Programming. Dr. -Ing. Abdalkarim Awad. Informatik 7 Rechnernetze und Kommunikationssysteme

SOCKET. Valerio Di Valerio

Lecture 05: Application Layer (Part 02) FTP, Peer-to-Peer, . Dr. Anis Koubaa

Chapter 2 Application Layer

Interprocess Communication

Chapter 2 Application Layer

EC441 Fall 2018 Introduction to Computer Networking Chapter 2: Application Layer

Review. Preview. Closing a TCP Connection. Closing a TCP Connection. Port Numbers 11/27/2017. Packet Exchange for TCP Connection

Network Communication

Goal and A sample Network App

Application Layer. Chapter 2. Computer Networking: A Top Down Approach. A note on the use of these Powerpoint slides:

Chapter 2 Application Layer

Chapter 2 Application Layer

Connections. Topics. Focus. Presentation Session. Application. Data Link. Transport. Physical. Network

Protocol Layers, Security Sec: Application Layer: Sec 2.1 Prof Lina Battestilli Fall 2017

CMPE 150/L : Introduction to Computer Networks. Chen Qian Computer Engineering UCSC Baskin Engineering Lecture 4

Java Network Programming

A Client-Server Exchange

Chapter 2 Application Layer

Introduction to Sockets 9/25/14

A set of processes distributed over a network that communicate via messages. Processes communicate via services offered by the operating system

Hybrid of client-server and P2P. Pure P2P Architecture. App-layer Protocols. Communicating Processes. Transport Service Requirements

CMSC 322 Computer Networks Applications and End-To- End

CS 3516: Advanced Computer Networks

Group-A Assignment No. 6

Lecture 11. Transport Layer (cont d) Transport Layer 1

CSE 461 Module 11. Connections

Transport Layer. The transport layer is responsible for the delivery of a message from one process to another. RSManiaol

CSE 461 The Transport Layer

CSEP 561 Connections. David Wetherall

Systems software design NETWORK COMMUNICATIONS & RPC SYSTEMS

Sockets 15H2. Inshik Song

Application. Transport. Network. Link. Physical

FTP. Mail. File Transfer Protocol (FTP) FTP commands, responses. Electronic Mail. TDTS06: Computer Networks

ECE 4450:427/527 - Computer Networks Spring 2017

Interprocess Communication Mechanisms

Transport Layer. Chapter 3: Transport Layer

4. The transport layer

Chapter 2 Application Layer

Distributed Systems. 02. Networking. Paul Krzyzanowski. Rutgers University. Fall 2017

ECE 650 Systems Programming & Engineering. Spring 2018

Chapter 2 Application Layer

(Refer Slide Time: 1:09)

Interprocess Communication Mechanisms

Chapter 2 Application Layer

9th Slide Set Computer Networks

Transcription:

CSE 422 Notes, Set 2 These slides contain materials provided with the text: Computer Networking: A Top Down Approach,5 th edition, by Jim Kurose and Keith Ross, Addison-Wesley, April 2009. Additional figures are repeated, with permission, from Computer Networks, 2 nd through 4 th Editions, by A. S. Tanenbaum, Prentice Hall. The remainder of the materials were developed by Philip McKinley and modified by Dennis Phillips at Michigan State University Assignment: Read sections in Chapter 2 of Kurose-Ross. We will cover in this order: 2.1, 2.7, 2.5, 2.4, 2.2 1

Outline r Introduce r Socket Programming r Domain Name Service (DNS) r Standard Application-level Protocols email (SMTP) HTTP Some network applications e-mail web instant messaging remote login P2P file sharing multi-user network games streaming stored video clips social networks voice over IP real-time video conferencing grid computing 2

Creating a network app We write programs that run on (different) hosts communicate over network e.g., browser software communicates with web server software We do not need to (and are not able to) write software for network-core devices Network-core devices do not run user code Limiting applications on end systems facilitates rapid app development, distribution application transport network data link physical application transport network data link physical application transport network data link physical Client-server architecture Most common paradigm server: always-on host client/server permanent IP address server farms for scaling clients: communicate with server may be intermittently connected may have dynamic IP addresses Usually do not communicate directly with each other 3

Application-layer protocol defines: Types of messages exchanged, e.g., request, response Message syntax: what fields in messages & how fields are delineated Message semantics meaning of information in fields Rules for when and how processes send & respond to messages Public-domain protocols: defined in RFCs allows for interoperability e.g., HTTP, SMTP, BitTorrent Outline Introduce Socket Programming Domain Name Service (DNS) Standard Application-level Protocols email (SMTP) HTTP 4

Application Programming Interfaces The TCP/IP protocol suite provides only the protocols that can be used by processes to communicate across a network. Though standarized, how these protocols are implemented is system specific Transport protocols and IP are typically implemented in the operating system. Hence, an API is needed to provide user processes with access to these protocols Low-level Interfaces Sockets -developed at Berkeley by Bill Joy and others (1981). Incorporated into BSD Unix and all derivatives, also supported in Windows, Mac OS X, etc. Key concept: make network access look much like file access. Technology-specific APIs E.g., ATM LANs, special LANs for compute clusters, and so on. 5

High-Level APIs Remote Procedure Call (RPC) message passing appears as procedure calling client accesses remote server through procedure call interface. typically implemented as a library atop sockets Object-oriented network programming Java.net class library OO middleware platforms such as CORBA Java Remote Method Invocation (RMI) Introduction to Sockets A socket is a kernel data structure, accessed via a file descriptor, that defines a bi-directional endpoint of communication Sockets are used as a basic building block for interprocess communication The kernel data structure contains state information regarding the socket has associated lists of send and receive buffers accesses transport functions directly 6

Socket programming goal: learn how to build client/server applications that communicate using sockets socket: door between application process and end-end-transport protocol application process socket application process controlled by app developer transport network link physical Internet transport network link physical controlled by OS 2-14 socket() system call A socket is created using the socket() call, which takes as parameters: protocol family type of communication specific protocol (often implicit) socket() returns a file descriptor A socket is created without a name a socket name is a triple: class (a.k.a. family), IP address, port number a name can be affixed to the socket after it is created by invoking the bind() system call 7

Protocol Families Internet Domain (AF_INET) interprocess communication among different hosts socket name includes internet address and port some port numbers are reserved for system use (see /etc/services) Unix Domain (AF_UNIX, aka AF_LOCAL) UNIX system internal protocols interprocess communication within same host socket name is a file pathname INET Socket types datagram socket (SOCK_DGRAM) unreliable datagram communication record boundary (fixed maximum) is preserved implemented using the UDP protocol stream socket (SOCK_STREAM) reliable virtual circuit communication record boundary is not preserved implemented using the TCP protocol raw socket (SOCK_RAW) direct interface to the IP protocol super-user (administrator) only, for new protocol development 8

INET socket names Name Components Protocol family (AF_INET) IP address Port number (can be chosen by OS) Socket must have a name in order to receive data Naming is done via bind() system call or implicit bind, discussed later. Socket programming basics Initial receiver (which we will call the server) must be running before the initial sender (the client) can (successfully) send anything to it. Server must have a socket through which it receives and sends segments Similarly, the client needs a socket The server socket is locally identified with (bound to) a port number Analogous to the mailbox number Client needs to know the server s IP address and port number. 9

Socket programming with UDP UDP: no connection between client and server sending application specifies the IP address and port of the destination the OS places these in the header of each outgoing datagram OS also places IP address and port of the sending socket in the header of each datagram Server can extract IP address, port of sender from received datagram Note: the official terminology for a UDP packet is datagram. Some texts refer to UDP segments, but the term segment usually applies to parts of TCP data streams A few notes about port numbers A port number is just a (16-bit) number; it has nothing to do with instances of physical hardware or even data structures Port numbers 0 to 1023 are well-known and reserved for standardized applications; they are not available to regular users e.g., port 80? When invoking bind(), an application program can specify the port number to be bound to the socket. If already in use? A parameter of 0 means: let OS choose an available port number. 10

Well Knows Ports IANA is the registry for Network Services https://www.iana.org/assignments/servicenames-port-numbers/service-names-portnumbers.xhtml FTP TCP 20/21 SSH TCP 22 SMTP TCP 25 DNS UDP/TCP 53 DHCP UDP 67/68 HTTP TCP 80 POP TCP 110 NTP TCP 123 IMAP TCP 143 LDAP TCP 389 HTTPS TCP 443 Example: UDP receiver 11

UDP receiver (cont.) UDP receiver (cont.) 12

UDP receiver (cont.) Example UDP sender 13

UDP sender (cont.) UDP observations & questions Both sender and receiver use datagram sockets Dest IP and port are explicitly included with the outgoing datagram. Question: how did the receiver (server) know the port number of the sender (client), if the client s socket was never bound? Can multiple clients send to the same server program at the same port? 14

Socket programming with TCP Client (active side) must connect to server (passive side) server process must first be already running server must have created a socket that receives the client s connection request Client contacts server by: creating a local TCP socket issuing a connect() system call, specifying IP address of server socket port number of server socket Server actions: create and bind a name to the receiving socket Await connection request Upon receipt, TCP creates new socket for the server process to communicate with this client allows server to talk with multiple clients on different sockets all have same server port number more on this later Stream socket Passive side Await (listen for) connections Use listen() system call to prepare operating system for connection requests Parameters: socket descriptor backlog: defines the maximum length the queue of pending connections (usually 5) 15

Passive side (cont.) Use the accept() system call socket descriptor name (family, host addr, port)? length of name Extracts the first connection on the queue of pending connections, creates a new socket, and allocates/returns a new file descriptor for the socket. Normally blocks, but this can be turned off Returns file descriptor of a new socket. Stream socket active side Initiate a connection on a socket Use the connect() system call socket descriptor name (family, host addr, port) length of name Connect on a datagram socket (??) Errors ETIMEOUT ECONNREFUSED ENETDOWN or EHOSTDOWN ENETUNREACH or EHOSTREACH 16

Transferring data Transmitting write() as for files send() uses flags to specify such requests as out-of-band transmission (MSG OOB) Receiving read() as for files recv() uses flags to specify such requests as examining data without reading it (MSG PEEK) TCP Example (passive side) 17

TCP Example (passive side) TCP Example (active side) 18

TCP active side (cont.) Server example (passive side) 19

Server passive side (cont.) Server example (active side) 20

Server active side (cont.) TCP/socket summary and a question Active and passive sides use stream sockets Passive side does bind(), listen() and accept() Active side must connect() to passive side Once connected, either side can read and write. When the passive side accepts a connection, it creates a new socket, but with the same port number as the original socket. Question: So, if packets are arriving from different clients, but all with the same destination port number, how does the OS know which socket which socket each belongs to? 21

Socket programming Two socket types for two transport services: UDP: unreliable datagram TCP: reliable, byte stream-oriented Application Example: 1. client reads a line of characters (data) from its keyboard and sends data to server 2. server receives the data and converts characters to uppercase 3. server sends modified data to client 4. client receives modified data and displays line on its screen Socket programming with UDP UDP: no connection between client & server no handshaking before sending data sender explicitly attaches IP destination address and port # to each packet receiver extracts sender IP address and port# from received packet UDP: transmitted data may be lost or received out-of-order Application viewpoint: UDP provides unreliable transfer of groups of bytes ( datagrams ) between client and server 22

Client/server socket interaction: UDP server (running on serverip) create socket, port= x: serversocket = socket(af_inet,sock_dgram) read datagram from serversocket write reply to serversocket specifying client address, port number client create socket: clientsocket = socket(af_inet,sock_dgram) Create datagram with server IP and port=x; send datagram via clientsocket read datagram from clientsocket close clientsocket Example app: UDP client include Python s socket library create UDP socket for server get user keyboard input Attach server name, port to message; send into socket read reply characters from socket into string print out received string and close socket Python UDPClient from socket import * servername = hostname serverport = 12000 clientsocket = socket(af_inet, SOCK_DGRAM) message = raw_input( Input lowercase sentence: ) clientsocket.sendto(message.encode(), (servername, serverport)) modifiedmessage, serveraddress = clientsocket.recvfrom(2048) print modifiedmessage.decode() clientsocket.close() 23

Example app: UDP server create UDP socket bind socket to local port number 12000 loop forever Read from UDP socket into message, getting client s address (client IP and port) send upper case string back to this client Python UDPServer from socket import * serverport = 12000 serversocket = socket(af_inet, SOCK_DGRAM) serversocket.bind(('', serverport)) print ( The server is ready to receive ) while True: message, clientaddress = serversocket.recvfrom(2048) modifiedmessage = message.decode().upper() serversocket.sendto(modifiedmessage.encode(), clientaddress) Python Socket programming with TCP client must contact server server process must first be running server must have created socket (door) that welcomes client s contact client contacts server by: Creating TCP socket, specifying IP address, port number of server process when client creates socket: client TCP establishes connection to server TCP when contacted by client, server TCP creates new socket for server process to communicate with that particular client allows server to talk with multiple clients source port numbers used to distinguish clients (more in Chap 3) application viewpoint: TCP provides reliable, in-order byte-stream transfer ( pipe ) between client and server 24

Python Client/server socket interaction: TCP server (running on hostid) client create socket, port=x, for incoming request: serversocket = socket() wait for incoming connection request connectionsocket = serversocket.accept() read request from connectionsocket write reply to connectionsocket close connectionsocket TCP connection setup create socket, connect to hostid, port=x clientsocket = socket() send request using clientsocket read reply from clientsocket close clientsocket 2-50 Python Example app: TCP client create TCP socket for server, remote port 12000 No need to attach server name, port Python TCPClient from socket import * servername = servername serverport = 12000 clientsocket = socket(af_inet, SOCK_STREAM) clientsocket.connect((servername,serverport)) sentence = raw_input( Input lowercase sentence: ) clientsocket.send(sentence.encode()) modifiedsentence = clientsocket.recv(1024) print ( From Server:, modifiedsentence.decode()) clientsocket.close() 2-51 25

Python Example app: TCP server create TCP welcoming socket server begins listening for incoming TCP requests loop forever server waits on accept() for incoming requests, new socket created on return read bytes from socket (but not address as in UDP) close connection to this client (but not welcoming socket) Python TCPServer from socket import * serverport = 12000 serversocket = socket(af_inet,sock_stream) serversocket.bind((,serverport)) serversocket.listen(1) print The server is ready to receive while True: connectionsocket, addr = serversocket.accept() sentence = connectionsocket.recv(1024).decode() capitalizedsentence = sentence.upper() connectionsocket.send(capitalizedsentence. encode()) connectionsocket.close() 2-52 26