CLIENT-SIDE PROGRAMMING

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

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

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

Tutorial on Socket Programming

TCP: Three-way handshake

Socket Programming TCP UDP

CSE 124 Discussion Section Sockets Programming 10/10/17

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

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

CSE 333 SECTION 6. Networking and sockets

Context. Distributed Systems: Sockets Programming. Alberto Bosio, Associate Professor UM Microelectronic Departement

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

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

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

Unix Network Programming

CSE 333 SECTION 8. Sockets, Network Programming

CSE 333 SECTION 7. Client-Side Network Programming

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

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

Socket Programming for TCP and UDP

Socket Programming(2/2)

Programming with TCP/IP. Ram Dantu

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

A Client-Server Exchange

Lab 0. Yvan Petillot. Networks - Lab 0 1

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

CSC209H Lecture 9. Dan Zingaro. March 11, 2015

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

CS321: Computer Networks Introduction to Application Layer

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

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

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

Hyo-bong Son Computer Systems Laboratory Sungkyunkwan University

CSE 333 SECTION 7. Client-Side Network Programming

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

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

CS 428/528 Computer Networks Lecture 01. Yan Wang

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

CS321: Computer Networks Socket Programming

C Structures in Practice

Sockets. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Writing Network Applications using the TCP/IP Protocol Stack: Socket Programming

CSE 333 Section 3. Thursday 12 April Thursday, April 12, 12

System Programming. Sockets

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

The Berkeley Sockets API. Networked Systems Architecture 3 Lecture 4

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

CSE 333 Lecture 16 - network programming intro

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

Network Communication

CSc 450/550 Computer Networks Network Architectures & Client-Server Model

Network programming(i) Lenuta Alboaie

Communication. Sockets (Haviland Ch. 10)

Internet applications

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

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

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

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

CSE 333 Lecture network programming intro

Socket Programming. Sungkyunkwan University. Hyunseung Choo Copyright Networking Laboratory

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

Elementary TCP Sockets

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

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

CompSci 356: Computer Network Architectures Lecture 3: Hardware and physical links References: Chap 1.4, 1.5 of [PD] Xiaowei Yang

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

What s an API? Do we need standardization?

Network Programming in C. Networked Systems 3 Laboratory Sessions and Problem Sets

Network Socket Programming - 3 BUPT/QMUL

Systems software design NETWORK COMMUNICATIONS & RPC SYSTEMS

EEC-484/584 Computer Networks

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

CS 640: Computer Networking

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

CS 3516: Computer Networks

Network Socket Programming - 3 BUPT/QMUL

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

STUDY OF SOCKET PROGRAMMING

Client Server Computing

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

TCP Network Programming in C

Introduction to Socket Programming

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

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

Group-A Assignment No. 6

CSE 333 Lecture 8 - file and network I/O

Computer Networks Prof. Ashok K. Agrawala

IPv6 Porting Applications

ICT 6544 Distributed Systems Lecture 5

CSE 333 Section 8 - Client-Side Networking

CMPSC 311- Introduction to Systems Programming Module: Network Programming

Network Software Implementations

Programming guidelines on transition to IPv6

Sockets 15H2. Inshik Song

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

UNIX Network Programming. Overview of Socket API Network Programming Basics

TCP/IP Sockets in C: Practical Guide for Programmers. Computer Chat. Internet Protocol (IP) IP Address. Transport Protocols. Ports

ECE 435 Network Engineering Lecture 2

VP Verteilte Informationssysteme Message Based Communication Socket Basics

Communication Networks ( ) / Spring 2011 The Blavatnik School of Computer Science, Tel-Aviv University. Allon Wagner

Transcription:

CLIENT-SIDE PROGRAMMING George Porter Apr 11, 2018 ATTRIBUTION These slides are released under an Attribution-NonCommercial-ShareAlike 3.0 Unported (CC BY-NC-SA 3.0) Creative Commons license These slides incorporate material from: Practical TCP/IP Sockets in C, 2nd ed., by Donahoo and Calvert Computer Networks: A Systems Approach, 5e, by Peterson and Davie 1

ANNOUNCEMENTS HW 1 due April 20 th - Local copy of the autograder now available (see web page for details) Project 1 posted Don t forget Donahoo and Calvert readings! Outline 1. Client socket API 2. Demo: writing a simple client 2

SOCKETS API Socket Interface was originally provided by the Berkeley distribution of Unix Now supported in virtually all operating systems Each protocol provides a certain set of services, and the API provides a syntax by which those services can be invoked in this particular OS WHAT IS A SOCKET? What is a socket? The point where a local application process attaches to the network An interface between an application and the network An application creates the socket The interface defines operations for Creating a socket Attaching a socket to the network Sending and receiving messages through the socket Closing the socket 3

TRANSPORT PROTOCOLS Add services on top of IP User Datagram Protocol (UDP) Data checksum Best-effort Transmission Control Protocol (TCP) Data checksum Reliable byte-stream delivery Flow control Prevents receiver from being overloaded Congestion control Prevents the network from being overloaded PORTS Application WWW E-mail ssh Port 80 25 22 192.18.22.13 IP addresses identify hosts Host has many applications Ports (16-bit identifier) identify a process 4

CLIENT OVERVIEW Steps 1. Create network socket 2. Connect to the server 3. Send a message 4. Receive the response 5. Close the socket Socket API used 1. socket() 2. connect() struct sockaddr_in 3. send() 4. recv() 5. close() SOCKET FAMILIES AND TYPES Socket Family PF_INET denotes the Internet family PF_UNIX denotes the Unix pipe facility PF_PACKET denotes direct access to the network interface (i.e., it bypasses the TCP/IP protocol stack) Socket Type SOCK_STREAM is used to denote a byte stream SOCK_DGRAM is an alternative that denotes a message oriented service, such as that provided by UDP 5

Generic IP Specific 4/11/2018 CREATING A SOCKET int sockfd = socket(address_family, type, protocol); The socket number returned is the socket descriptor for the newly created socket int sockfd = socket (PF_INET, SOCK_STREAM, 0); int sockfd = socket (PF_INET, SOCK_DGRAM, 0); The combo of PF_INET and SOCK_STREAM implies TCP struct sockaddr { unsigned short sa_family; /* Address family (e.g., AF_INET) */ char sa_data[14]; /* Protocol-specific address information */ }; struct sockaddr_in { unsigned short sin_family; /* Internet protocol (AF_INET) */ unsigned short sin_port; /* Port (16-bits) */ struct in_addr sin_addr; /* Internet address (32-bits) */ char sin_zero[8]; /* Not used */ }; struct in_addr { unsigned long s_addr; /* Internet address (32-bits) */ }; sockaddr Family Blob 2 bytes 2 bytes 4 bytes 8 bytes sockaddr_in Family Port Internet address Not used 6

HANDY HELPER FUNCTIONS FOR ADDRESSES Converting IP addrs to/from strings Printable string to binary: int inet_pton(); Binary to printable string: const char * inet_ntop() Making the byte order consistent uint16_t htons(uint16_t hostshort); uint16_t ntohs(uint16_t netshort); CONNECTING SOCKETS int connect(int socket, const struct sockaddr *address, socklen_t address_len); socket is the descriptor address describes the destination address len is the size of address Blocking call: waits until a connection is established Q: What kinds of errors might occur here? 7

SENDING DATA ssize_t send(socket,buf,len,flags) We re using blocking semantics of send Always check that the right number of bytes were sent Returns the number of bytes that were copied to the operating system kernel for transmission RECEIVING RESPONSES ssize_t recv(int sockfd, void *buf, size_t len, int flags); Note: recv() receives at least one bytes from the socket It does not receive the same number of bytes that were sent via send (we ll see why in Chapter 7) Returns 0 when the client has closed the socket What does this mean? You have to keep reading from the socket until you ve received all the bytes you need 8

Outline 1. Client socket API 2. Demo: writing a simple client 9