COMP/ELEC 429/556 Introduction to Computer Networks

Similar documents
Assignment 2 Group 5 Simon Gerber Systems Group Dept. Computer Science ETH Zurich - Switzerland

I/O Models. Kartik Gopalan

Project 1: A Web Server Called Liso

CS118 Discussion Week 2. Taqi

CISC2200 Threads Spring 2015

CS118 Discussion 1A, Week 3. Zengwen Yuan Dodd Hall 78, Friday 10:00 11:50 a.m.

Any of the descriptors in the set {1, 4} have an exception condition pending

CSC209H Lecture 10. Dan Zingaro. March 18, 2015

Socket Programming for TCP and UDP

Εργαστήριο 9 I/O Multiplexing

BSD Sockets API. Mesut Ali ERGIN. Yeditepe University Information and Computer Science Department

ISA 563: Fundamentals of Systems Programming

Group-A Assignment No. 6

Network Games Part II. Architecture of Network Game

Types (Protocols) Associated functions Styles We will look at using sockets in C Java sockets are conceptually quite similar

Tutorial on Socket Programming

CSE 333 Lecture non-blocking I/O and select

SOCKET PROGRAMMING. What is a socket? Using sockets Types (Protocols) Associated functions Styles

CONCURRENCY MODEL. UNIX Programming 2014 Fall by Euiseong Seo

Redesde Computadores(RCOMP)

Ports under 1024 are often considered special, and usually require special OS privileges to use.

Redes de Computadores (RCOMP)

Version Control with Git and What is there in Project 1 PALLABI GHOSH COMPUTER NETWORKS RECITATION 1

Concurrent Programming. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Introduction to Socket Programming

Socket Programming. #In the name of Allah. Computer Engineering Department Sharif University of Technology CE443- Computer Networks

Topics for this Week

PROCESSES AND THREADS THREADING MODELS. CS124 Operating Systems Winter , Lecture 8

CONCURRENT PROGRAMMING. Lecture 5

// socket for establishing connections

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

Introduction to Berkeley Sockets

Global Employee Location Server

Simple network applications using sockets (BSD and WinSock) Revision 1 Copyright Clifford Slocombe

Introduction to Berkeley Sockets

CS631 - Advanced Programming in the UNIX Environment Interprocess Communication II

9/13/2007. Motivations for Sockets What s in a Socket? Working g with Sockets Concurrent Network Applications Software Engineering for Project 1

NETWORK AND SYSTEM PROGRAMMING. I/O Multiplexing: select and poll function

Networked Applications: Sockets. End System: Computer on the Net

ECE 650 Systems Programming & Engineering. Spring 2018

CS11 C++ DGC. Spring Lecture 6

CSMC 412. Computer Networks Prof. Ashok K Agrawala Ashok Agrawala Set 2. September 15 CMSC417 Set 2 1

Instruction Set Architecture (ISA) Data Types

EECS122 Communications Networks Socket Programming. Jörn Altmann

Overview. Setup and Preparation. Exercise 0: Four-way handshake

Operating Systems CMPSCI 377 Spring Mark Corner University of Massachusetts Amherst

December 8, epoll: asynchronous I/O on Linux. Pierre-Marie de Rodat. Synchronous/asynch. epoll vs select and poll

Introduction to Berkeley Sockets

10. I/O System Library

A Client-Server Exchange

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

Network Software Implementations

COMP/ELEC 429/556 Introduction to Computer Networks

Networked Applications: Sockets. Goals of Todayʼs Lecture. End System: Computer on the ʻNet. Client-server paradigm End systems Clients and servers

ECE 435 Network Engineering Lecture 2

Christian Tschudin (basierend auf einem Foliensatz von C. Jelger und T. Meyer) Departement Mathematik und Informatik, Universität Basel

Today: VM wrap-up Select (if time) Course wrap-up Final Evaluations

call connect call read call connect ret connect call fgets Client 2 blocks waiting to complete its connection request until after lunch!

CPS 214: Computer Networks. Slides by Adolfo Rodriguez

CSCE 455/855 Distributed Operating Systems

Network Programming in C: The Berkeley Sockets API. Networked Systems 3 Laboratory Sessions

CSE 333 Lecture fork, pthread_create, select

ECE 435 Network Engineering Lecture 2

I/O Multiplexing. Dec 2009

Socket Programming TCP UDP

UNIX Sockets. COS 461 Precept 1

EECS 482 Introduction to Operating Systems

Chapter 3: Client-Server Paradigm and Middleware

Computer Networks Prof. Ashok K. Agrawala

Key Points for the Review

Network programming(ii) Lenuta Alboaie

Project 3. Reliable Data Transfer over UDP. NTU CSIE Computer Networks 2011 Spring

CHETTINAD COLLEGE OF ENGINEERING AND TECHNOLOGY DEPARTMENT OF MCA QUESTION BANK UNIT 1

We start by looking at what s known as event-based programming: we write code that responds to events coming from a number of sources.

Asynchronous Events on Linux

Exception-Less System Calls for Event-Driven Servers

CS4700/CS5700 Fundaments of Computer Networks

G Honors Operating Systems

CS 33. More Network Programming. CS33 Intro to Computer Systems XXXI 1 Copyright 2017 Thomas W. Doeppner. All rights reserved.

UNIT III - APPLICATION DEVELOPMENT. TCP Echo Server

Three Basic Mechanisms for Creating Concurrent Flows. Systemprogrammering 2009 Föreläsning 10 Concurrent Servers. Process-Based Concurrent Server

Network Programming TDC 561

Lecture 8: Other IPC Mechanisms. CSC 469H1F Fall 2006 Angela Demke Brown

Socket Programming. CSIS0234A Computer and Communication Networks. Socket Programming in C

Topics. Lecture 8: Other IPC Mechanisms. Socket IPC. Unix Communication

NETWORK AND SYSTEM PROGRAMMING

Outline. Option Types. Socket Options SWE 545. Socket Options. Out-of-Band Data. Advanced Socket. Many socket options are Boolean flags

Advcan QNX Driver User Manual V1.02

Oral. Total. Dated Sign (2) (5) (3) (2)

UNIT IV- SOCKETS Part A

CMPSC 311- Introduction to Systems Programming Module: Network Programming

Architecture and Design of Distributed Dependable Systems TI-ARDI. POSA2: Reactor Architectural Pattern

A Socket Example. Haris Andrianakis & Angelos Stavrou George Mason University

Communication Networks

Socket Programming. What is a socket? Using sockets. Types (Protocols) Associated functions Styles

Programming Ethernet with Socket API. Hui Chen, Ph.D. Dept. of Engineering & Computer Science Virginia State University Petersburg, VA 23806

CPSC 427a: Object-Oriented Programming

Hyo-bong Son Computer Systems Laboratory Sungkyunkwan University

Servers: Concurrency and Performance. Jeff Chase Duke University

What s an API? Do we need standardization?

Transcription:

COMP/ELEC 429/556 Introduction to Computer Networks Creating a Network Application Some slides used with permissions from Edward W. Knightly, T. S. Eugene Ng, Ion Stoica, Hui Zhang 1

How to Programmatically Use the DNS System? Operating system comes to the rescue gethostbyname() gethostbyaddr() These functions are not re-entrant Cannot have 2 program threads calling them concurrently Call them in your main thread or use the more complicated threadsafe alternatives gethostbyname_r() and gethostbyaddr_r() On CLEAR, you can type man gethostbyname to get a detailed description of the function man stands for manual 2

How to Programmatically Send/Receive Data over the Internet? 3

Operating System comes to the rescue Reliable byte stream network communications service The most common model Underlies almost every network application you use 4

Reliable Byte Stream Model The elemental transmission unit is a byte (8 bits) Bytes are delivered reliably, first in first out We will learn how this is accomplished later bytes sent bytes received 0x3a 0xf2 0x12 Network Abstraction 5

Reliable Byte Stream Bytes are delivered without any notion of application message units Example 1 0x3a 0xf2 0x12 1st recv() got 0x12 2nd recv() got 0xf2, 0x3a Example 2 0x3a 0xf2 0x12 1st recv() got nothing due to timeout 2nd recv() got 0x12, 0xf2 3rd recv() got 0x3a 6

Application decides message format and how to interpret the byte stream E.g. Each message is a null (0x00) terminated string In this case, a program reads in bytes until encountering 0x00 to form a valid message 7

Project 1 Ping/Pong Message 0 15 16 31 size tv_sec tv_usec additional optional data 2 size bytes 0xf2 0x12 What is the size? 0x12f2 = 4,850 0xf212 = 61,970 Network byte order (a.k.a. Big endian) first byte sent/received is the most significant size is 0x12f2 = 4,850 8

Why the need to specify network byte ordering convention for numbers? CPUs may choose little-endian or big-endian format when storing numbers in registers and RAM Most Intel CPUs are little-endian (1 st byte least significant) Network byte ordering convention is big-endian (1 st byte most significant) The number 4,850 (0x12f2), which is stored in big-endian?... 0x12 0xf2... Big-endian lower address higher address... 0xf2 0x12... lower address higher address Little-endian 9

What about bit ordering? Which bit in a byte received over the network is most significant? OMG, not again! Bit ordering within a byte is handled entirely in hardware 10

Byte ordering conversion functions host order to network order htons() for short integer (i.e. 16 bit) htonl() for long integer (i.e. 32 bit) htobe64() for 64 bit integer network order to host order ntohs() for short integer (i.e. 16 bit) ntohl() for long integer (i.e. 32 bit) be64toh() for 64 bit integer Must be careful in deciding whether conversion is required Is a variable numeric? Is a numeric variable already stored in network byte order? These functions are no-op on CPUs that use network byte ordering (big-endian) for internal number representation But a program must compile and work regardless of CPU, so these functions have to be used for compatibility 11

How to Programmatically Send/Receive Data over the Internet? 12

Operating System comes to the rescue Socket API Refresh your memory of the mechanics of using socket for network communications 13

Overview of the Socket API Client Server create a descriptor socket socket create a descriptor bind associate with address and port number connect Connection request listen accept a new descriptor is created for this connection send, recv send, recv close close 14

How to support multiple simultaneous connections? 15

Operating System comes to the rescue Event-driven concurrency Refresh your memory of one way to create the illusion of concurrently handling multiple network conversations even on a uni-processor Another way is multi-threading Can achieve real concurrency on multi-processors Refer to COMP321 material A combination of event-driven concurrency and multithread concurrency is needed to achieve the highest server scalability 16

Event-Based Concurrent Servers Maintain a pool of descriptors Repeat the following forever: Block until: New connection request arrives on the listening descriptor New data arrives on an existing connected descriptor A connected descriptor is ready to be written to A timeout occurs (can be configured to have no timeout) If new connection request, add the new connection to the pool of connections If new data arrives, read any available data from the connection If descriptor is ready to be written, write whatever data is pending If timeout, do whatever is appropriate for timeout Can wait for input from local I/O (standard input) and remote I/O (socket) simultaneously! Many implementations: select(), poll(), epoll(), etc. 17

Event-Based Concurrent I/O int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout); readfds, writefds Opaque bit vector (max FD_SETSIZE bits) that indicates membership in a descriptor set If bit k is 1, then descriptor k is a member of the descriptor set nfds Maximum descriptor value + 1 in the set Tests descriptors 0, 1, 2,..., nfds - 1 for set membership select() returns the number of ready descriptors and sets each bit of readfds, writefds to indicate the ready status of its corresponding descriptor 18

Macros for Manipulating Set Descriptors void FD_ZERO(fd_set *fdset); Turn off all bits in fdset void FD_SET(int fd, fd_set *fdset); Turn on bit fd in fdset void FD_CLR(int fd, fd_set *fdset); Turn off bit fd in fdset int FD_ISSET(int fd, *fdset); Is bit fd in fdset turned on? 19