Overview. Administrative. * HW# 5 Due next week. * HW# 5 : Any Questions. Topics. * Client Server Communication. * 12.

Similar documents
System Programming. Sockets

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

Introduction to Socket Programming

TCP: Three-way handshake

Tutorial on Socket Programming

Socket Programming TCP UDP

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

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

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

Socket Programming for TCP and UDP

sottotitolo Socket Programming Milano, XX mese 20XX A.A. 2016/17 Federico Reghenzani

CSE 124 Discussion Section Sockets Programming 10/10/17

Session NM056. Programming TCP/IP with Sockets. Geoff Bryant Process software

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

Programming with TCP/IP. Ram Dantu

Unix Network Programming

Socket Programming. Joseph Cordina

CS118 Discussion 1B, Week 1. Taqi Raza BUNCHE 1209B, Fridays 12:00pm to 1:50pm

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

ECE 435 Network Engineering Lecture 2

CSE 333 SECTION 8. Sockets, Network Programming

Hyo-bong Son Computer Systems Laboratory Sungkyunkwan University

CLIENT-SIDE PROGRAMMING

ECE 435 Network Engineering Lecture 2

CSC209H Lecture 9. Dan Zingaro. March 11, 2015

Lecture 7. Followup. Review. Communication Interface. Socket Communication. Client-Server Model. Socket Programming January 28, 2005

Introduction to Socket Programming

CS 43: Computer Networks. 05: Socket Programming September 12-14, 2018

Sockets. Dong-kun Shin Embedded Software Laboratory Sungkyunkwan University Embedded Software Lab.

Lecture 2. Outline. Layering and Protocols. Network Architecture. Layering and Protocols. Layering and Protocols. Chapter 1 - Foundation

Sockets. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Chapter 6. The Transport Layer. Transport Layer 3-1

Outline. Operating Systems. Socket Basics An end-point for a IP network connection. Ports. Network Communication. Sockets and the OS

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

CSE 333 SECTION 7. Client-Side Network Programming

CS4700/CS5700 Fundamentals of Computer Networking

CS 640: Computer Networking

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

WinSock. What Is Sockets What Is Windows Sockets What Are Its Benefits Architecture of Windows Sockets Network Application Mechanics

UNIT IV- SOCKETS Part A

CSE 333 SECTION 7. C++ Virtual Functions and Client-Side Network Programming

Topics for this Week

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

Communication. Sockets (Haviland Ch. 10)

MSc Integrated Electronics Networks Assignment. Investigation of TCP/IP Sockets and Ports. Gavin Cameron

Systems software design NETWORK COMMUNICATIONS & RPC SYSTEMS

Outline. Distributed Computing Systems. Socket Basics (1 of 2) Socket Basics (2 of 2) 3/28/2014

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

UNIX Network Programming. Overview of Socket API Network Programming Basics

PA #2 Reviews. set_name, get_name, del_name. Questions? Will be modified after PA #4 ~

Network Programming November 3, 2008

Outline. Distributed Computer Systems. Socket Basics An end-point for a IP network connection. Ports. Sockets and the OS. Transport Layer.

SOCKETS. COMP750 Distributed Systems

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

A. Basic Function Calls for Network Communications

How do we Communicate? Introduction to Unix Network Programming. What does Alice do? What does Bob do? Two simplest networking programs

Department of Computer Science

The BSD UNIX Socket Interface (CS 640 Lecture) Assignment 1. Interprocess Communication (IPC) Work Individually (no groups)

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

Interprocess Communication

CSE 333 SECTION 6. Networking and sockets

Client Server Computing

CSE 333 Lecture 16 - network programming intro

Socket Programming 2007/03/28

NETWORK PROGRAMMING. Instructor: Junaid Tariq, Lecturer, Department of Computer Science

Overview. Administrative. * MQ solutions on the web. * Grades so far. Topics: * What is Client-Server Architecture?

Tutorial 2. Linux networking, sk_buff and stateless packet filtering. Roei Ben-Harush Check Point Software Technologies Ltd.

Client-server model The course that gives CMU its Zip! Network programming Nov 27, Using ports to identify services.

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

Network Communication

What s an API? Do we need standardization?

Lecture 7. Berkeley Socket Programming

Network programming(i) Lenuta Alboaie

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

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

CMPSC 311- Introduction to Systems Programming Module: Network Programming

UNIX Sockets. Developed for the Azera Group By: Joseph D. Fournier B.Sc.E.E., M.Sc.E.E.

Introduction to Network Programming using C/C++

TCP Network Programming in C

Lab 0. Yvan Petillot. Networks - Lab 0 1

CSE 333 Lecture network programming intro

Announcements. CS 5565 Network Architecture and Protocols. Queuing. Demultiplexing. Demultiplexing Issues (1) Demultiplexing Issues (2)

Network Socket Programming - 2 BUPT/QMUL

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

The Berkeley Sockets API. Networked Systems Architecture 3 Lecture 4

Sockets. 1 Introduction. (Reference:, Gray Chapter 10) Network Programming Lecture Notes by. Turhan TUNALI

#1 socket_server.c socket_client.c

IP Addresses, DNS. CSE 333 Summer Teaching Assistants: Renshu Gu William Kim Soumya Vasisht

Lecture 3 Overview! Last Lecture! TCP/UDP and Sockets introduction!

Server-side Programming

Network Software Implementations

IP Addresses, DNS. CSE 333 Spring Instructor: Justin Hsia

ICT 6544 Distributed Systems Lecture 5

CSE 333 SECTION 7. Client-Side Network Programming

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

Problem 1: Concepts (Please be concise)

Computer Networks Prof. Ashok K. Agrawala

Application Programming Interfaces

CSE 333 Section 8 - Client-Side Networking

CMPSC 311- Introduction to Systems Programming Module: Network Programming

Transcription:

Overview Administrative * HW# 5 Due next week * HW# 5 : Any Questions Topics * Client Server Communication * 12.3 ISO/OSI Layers * 12.4 UICI Implementations * App. B (UICI : Socket Implementation) * 12.4 Sockets * 12.8 UICI and thread safety Readings: * 12.4 UICI Implementations * App. B (UICI : Socket Implementation) * 12.8 UICI and thread safety

2 12.3 ISO/OSI Layers Idea * Network protocols are complex * Must deal with many types of errors and services * Decompose as a set of layers * Lower layers provide services to upper layers * Lower layers hide details, reduce complexity Layers - See Figure in the textbook * Physical * Data link * Network * Transport

3 12.4 Sockets History * early-1980s: BSD 4.1 introduced it * mid-1980s: BSD 4.2 standardized it * Available in most Unix & Windows systems - linking: -lsocket, -lnsl * Part of Spec 1170 * But not standardized by POSIX yet Sockets vs. File Descriptors * read/write operations are similar * creation is more complex - open() for file descriptor Sockets vs. UICI Concepts * Sockets = port * a handle to network communication channel

4 12.4 Sockets vs. UICI Communication-style * UICI: Connection-based * Sockets: Connection-based or connection-less Server Design (Section 12.1) - UICI: Server design 3, 4, 5 - Socket: designs 1, 2, 3, 4, 5 Blocking * UICI: many system calls * Socket: fewer system calls are blocking System calls (Table 12.2, pp. 444) * read/write is simple in both * Connection setup more complex in sockets

5 12.4 Sockets - Client System Calls UICI Client (Program 12.4, pp. 442-3) fd = u_connect(portnumber, server_hostname); u_read(fd,...,...); u_close(fd); socket based UICI implementation * See u_close (pp. 607) - calls close() on file descriptor * See u_read (pp. 607) - calls read() on file descriptor - checks for signal interuptts See u_connect (Program 12.7, pp. 452-3 or 606-7) sock = socket(af_inet, SOCK_STREAM, 0); /* initialize struct server */ connect(sock, &server, sizeof(server)); return sock;

6 12.4 Sockets - Basic System Calls System call socket() - Synopsis (pp. 448) int socket(int af, int type, int protocol) * Purpose: Create a socket, i.e. a port * Return value: file descriptor to new socket * Argument 1: address family or domain - AF_INET for network communication - AF_UNIX for single unix system to mimic pipe/fifo * Argument 2: communication-type - SOCK_STREAM for connection based - SOCK_DGRAM for connection less * Argument 3: protocol - value 0 => system will choose appropriate one Example Usage * Example 12.5 (pp. 448)

7 12.4 Sockets - Basic System Calls System call connect() int connect(int s, struct sockaddr *name, int namelen) * Purpose: form a network communication channel - associate client port with a server port * Argument 1: file descriptor for client s socket * Argument 2: server s address (host, port) * Argument 3: size of 2nd argument * Returns 0 on success, -1 on error Server address * struct sockaddr_in (pp. 449) * sin_family - AF_INET * sin_port - port/socket number * sin_addr - hostname, e.g. deca.cs.umn.edu * sin_zero - filler for legacy compatibility

8 12.4 Sockets - Other System Calls Other utility system calls * gethostbyname() - synopsis on pp. 452 * Argument: symbolic hostname * Returns: a structure - h_addr_list[] = network addresses used by this host - h_length = number of bytes in address * gethostbyname_r() - thread-safe version

9 12.4 Sockets - Byte Ordering Network Byte Order for Numbers * little endian - bytes stored in increasing addresses - Ex. Intel, Vax * big endian - Other architectures Network Byte Order * Standard format, e.g. big-endian Conversion Routines #include <sys/types.h> #include <netinet/in.h> u_long htonl(u_long hostlong); u_short htons(u_short hostshort); u_long ntohl(u_long netlong); u_short ntohs(u_short netshort); Implementation Details * These functions are macros * little-endian machines - change bytes to network byte order. * On big-endian machines no change needed

10 12.4 Sockets - Connection based Server UICI Server (Program 12.2, pp. 439-440) listenfd = u_open(portnumber); communfd = u_listen(listenfd, client); u_read(communfd,...,...); u_close(communfd); socket based UICI implementation * Already saw See u_close and u_read (pp. 607) * See u_open (Program 12.7, pp. 450 ) - uses socket(), bind(), listen() * See u_listen (Program 12.6, pp. 451 ) - uses accept() Let us look at bind, listen, accept

11 12.4 Sockets - Server System call System call bind() int bind(int s, const struct sockaddr *a, size_t a_len) * Purpose: Associate a socket file descriptor to - a network communication channel (e.g. port) * Argument1: file descriptor for socket * Argument2: address of server (hostname, port) * Argument3: length of argument 2 * Returns 0 on success, -1 on error System call listen() int listen(int s, int backlog) * Purpose: Specify number of client request to be - buffered before server refuses a connection * Note: Quite different from u_listen() * Argument1: file descriptor for public socket * Argument2: buffer size * Returns 0 on success, -1 on error Implmentation of u_open (Program 12.5, pp.450)

12 12.4 Sockets - Server System call System call accept() int accept(int s, struct sockaddr *a, int *a_len) * Purpose: Server waits for client requests * Returns a file descriptor - for communication with the client * Argument1: file descriptor for socket * Argument2: address of client requesting connection - Filled by accept() * Argument3: length of argument 2 Implmentation of u_listen (Program 12.6, pp.451) * Uses accept() * Uses gethostbyaddr() : Synopis pp. 451 - to get symbolic name of host of client

! 13 12.4 Sockets - Client Protocol Summary Summary of Client Side Protocol Steps on Client Side * 1.Create a socket - with the socket() system call * 2.Connect the socket to the address of the server - using the connect() system call * 3.Send and receive data. - There are a number of ways to do this, - e.g. the read() and write() system calls.

" # 14 12.4 Sockets - Server Protocol SUmmary Summary of Server Side Protocol Steps on Server Side * 1.Create a socket with the socket() system call * 2.Bind the socket to an address - using the bind() system call. - address = <port number, host machine> * 3.Specify buffer size for pending connections - with the listen() system call * 4.Accept a connection with the accept() system call. - typically blocks until a client connects with the server. * 5.Send and receive data

$ % 15 12.8 UICI - Thread Safety Implementation of UICI has unsafe system calls * gethostbyname() - pp. 452 * gethostbyname_r() - thread-safe version Thread safe UICI * u_open_r * u_close_r * u_connect_r * u_listen_r * u_read_r * u_write_r