UNIX Sockets. COS 461 Precept 1



Similar documents
Tutorial on Socket Programming

ICT SEcurity BASICS. Course: Software Defined Radio. Angelo Liguori. SP4TE lab.

Socket Programming. Srinidhi Varadarajan

The POSIX Socket API

Socket Programming. Kameswari Chebrolu Dept. of Electrical Engineering, IIT Kanpur

Introduction to Socket Programming Part I : TCP Clients, Servers; Host information

Overview. Socket Programming. Using Ports to Identify Services. UNIX Socket API. Knowing What Port Number To Use. Socket: End Point of Communication

Networks. Inter-process Communication. Pipes. Inter-process Communication

ELEN 602: Computer Communications and Networking. Socket Programming Basics

Lab 4: Socket Programming: netcat part

Introduction to Socket programming using C

Unix Network Programming

Programmation Systèmes Cours 9 UNIX Domain Sockets

Socket Programming in C/C++

Socket Programming. Request. Reply. Figure 1. Client-Server paradigm

Operating Systems Design 16. Networking: Sockets

Porting applications & DNS issues. socket interface extensions for IPv6. Eva M. Castro. ecastro@dit.upm.es. dit. Porting applications & DNS issues UPM

NS3 Lab 1 TCP/IP Network Programming in C

Implementing Network Software

Computer Networks Network architecture

IT304 Experiment 2 To understand the concept of IPC, Pipes, Signals, Multi-Threading and Multiprocessing in the context of networking.

Lecture 2-ter. 2. A communication example Managing a HTTP v1.0 connection. G.Bianchi, G.Neglia, V.Mancuso

VMCI Sockets Programming Guide VMware ESX/ESXi 4.x VMware Workstation 7.x VMware Server 2.0

Application Architecture

INTRODUCTION UNIX NETWORK PROGRAMMING Vol 1, Third Edition by Richard Stevens

Generalised Socket Addresses for Unix Squeak

Web Browsing Examples. How Web Browsing and HTTP Works

Socket = an interface connection between two (dissimilar) pipes. OS provides this API to connect applications to networks. home.comcast.

Network Programming with Sockets. Process Management in UNIX

TCP/IP - Socket Programming

What is CSG150 about? Fundamentals of Computer Networking. Course Outline. Lecture 1 Outline. Guevara Noubir noubir@ccs.neu.

Chapter 3. Internet Applications and Network Programming

DESIGN AND IMPLEMENT AND ONLINE EXERCISE FOR TEACHING AND DEVELOPMENT OF A SERVER USING SOCKET PROGRAMMING IN C

Writing a C-based Client/Server

BSD Sockets Interface Programmer s Guide

M3-R3: INTERNET AND WEB DESIGN

Limi Kalita / (IJCSIT) International Journal of Computer Science and Information Technologies, Vol. 5 (3), 2014, Socket Programming

Lab 3.4.2: Managing a Web Server

1. When will an IP process drop a datagram? 2. When will an IP process fragment a datagram? 3. When will a TCP process drop a segment?

Project 1: Implement a simple hosts framework using UNIX TCP Sockets to demonstrate the concept of Mobile Agents

Concurrent Server Design Alternatives

Elementary Name and Address Conversions

COS 318: Operating Systems. I/O Device and Drivers. Input and Output. Definitions and General Method. Revisit Hardware

3.5. cmsg Developer s Guide. Data Acquisition Group JEFFERSON LAB. Version

SMTP-32 Library. Simple Mail Transfer Protocol Dynamic Link Library for Microsoft Windows. Version 5.2

I/O Device and Drivers

System Calls and Standard I/O

15-441: Computer Networks Homework 1

Introduction to Network. Topics

Elementary Name and Address. Conversions

Chapter 25 Domain Name System Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Direct Sockets. Christian Leber Lehrstuhl Rechnerarchitektur Universität Mannheim

Project 4: IP over DNS Due: 11:59 PM, Dec 14, 2015

Linux and the Internet, Servers, Ports, Firewalls

CSE 333 SECTION 6. Networking and sockets

Objectives of Lecture. Network Architecture. Protocols. Contents

Network-Oriented Software Development. Course: CSc4360/CSc6360 Instructor: Dr. Beyah Sessions: M-W, 3:00 4:40pm Lecture 2

Communication Networks. Introduction & Socket Programming Yuval Rochman

Denial Of Service. Types of attacks

Project #2. CSE 123b Communications Software. HTTP Messages. HTTP Basics. HTTP Request. HTTP Request. Spring Four parts

Use Domain Name System and IP Version 6

Linux Kernel Architecture

Session NM059. TCP/IP Programming on VMS. Geoff Bryant Process Software

MINIMUM NETWORK REQUIREMENTS 1. REQUIREMENTS SUMMARY... 1

Domain Name System (1)! gethostbyname (2)! gethostbyaddr (2)!

IMF Tune Quarantine & Reporting Running SQL behind a Firewall. WinDeveloper Software Ltd.

DNS Resolving using nslookup

GSM. Quectel Cellular Engine. GSM TCPIP Application Notes GSM_TCPIP_AN_V1.1

Dynamic Host Configuration Protocol (DHCP) 02 NAT and DHCP Tópicos Avançados de Redes

IPv6 Enabling CIFS/SMB Applications

Web Development. Owen Sacco. ICS2205/ICS2230 Web Intelligence

CS 213, Fall 2000 Lab Assignment L5: Logging Web Proxy Assigned: Nov. 28, Due: Mon. Dec. 11, 11:59PM

Network Programming with Sockets. Anatomy of an Internet Connection

Abstract. Introduction. Section I. What is Denial of Service Attack?

Life of a Packet CS 640,

Network Programming TDC 561

Web. Services. Web Technologies. Today. Web. Technologies. Internet WWW. Protocols TCP/IP HTTP. Apache. Next Time. Lecture # Apache.

Single Pass Load Balancing with Session Persistence in IPv6 Network. C. J. (Charlie) Liu Network Operations Charter Communications

Linux Driver Devices. Why, When, Which, How?

CS 416: Opera-ng Systems Design

DNS Domain Name System

Network Technologies

Network Programming using sockets

1 hours, 30 minutes, 38 seconds Heavy scan. All scanned network resources. Copyright 2001, FTP access obtained

Internet Control Protocols Reading: Chapter 3

DEPLOYMENT GUIDE Version 1.4. Configuring IP Address Sharing in a Large Scale Network: DNS64/NAT64

Chapter 14 Analyzing Network Traffic. Ed Crowley

First Midterm for ECE374 03/09/12 Solution!!

Network Traffic Analysis using HADOOP Architecture. Zeng Shan ISGC2013, Taibei

Agenda. Distributed System Structures. Why Distributed Systems? Motivation

IP Network Layer. Datagram ID FLAG Fragment Offset. IP Datagrams. IP Addresses. IP Addresses. CSCE 515: Computer Network Programming TCP/IP

COS 461: Computer Networks

Operating Systems and Networks

The Transport Layer. Antonio Carzaniga. October 24, Faculty of Informatics University of Lugano Antonio Carzaniga

Computer Networks/DV2 Lab

Transcription:

UNIX Sockets COS 461 Precept 1

Clients and Servers Client program Running on end host Requests service E.g., Web browser Server program Running on end host Provides service E.g., Web server GET /index.html Site under construclon 2

Clients Are Not Necessarily Human Example: Web crawler (or spider) Automated client program Tries to discover & download many Web pages Forms the basis of search engines like Google Spider client Start with a base list of popular Web sites Download the Web pages Parse the HTML files to extract hypertext links Download these Web pages, too And repeat, and repeat, and repeat 3

Client- Server CommunicaLon Client somelmes on IniLates a request to the server when interested E.g., Web browser on your laptop or cell phone Doesn t communicate directly with other clients Needs to know server s address Server is always on Services requests from many client hosts E.g., Web server for the www.cnn.com Web site Doesn t inilate contact with the clients Needs fixed, known address 4

Client and Server Processes Program vs. process Program: colleclon of code Process: a running program on a host CommunicaLon between processes Same end host: inter- process communicalon Governed by the operalng system on the end host Different end hosts: exchanging messages Governed by the network protocols Client and server processes Client process: process that inilates communicalon Server process: process that waits to be contacted 5

Delivering the Data: Division of Labor Network Deliver data packet to the deslnalon host Based on the deslnalon IP address OperaLng system Deliver data to the deslnalon socket Based on the deslnalon port number (e.g., 80) ApplicaLon Read data from and write data to the socket Interpret the data (e.g., render a Web page) 6

Socket: End Point of CommunicaLon Sending message from one process to another Message must traverse the underlying network Process sends and receives through a socket In essence, the doorway leading in/out of the house Socket as an ApplicaLon Programming Interface Supports the crealon of network applicalons User process User process socket OperaLng System socket OperaLng System 7

IdenLfying the Receiving Process Sending process must idenlfy the receiver The receiving end host machine The specific socket in a process on that machine Receiving host DesLnaLon address that uniquely idenlfies the host An IP address is a 32- bit quanlty Receiving socket Host may be running many different processes DesLnaLon port that uniquely idenlfies the socket A port number is a 16- bit quanlty 8

Using Ports to IdenLfy Services Client host" Client" Service request for" 128.2.194.242:80" (i.e., the Web server)" Server host 128.2.194.242" OS" Web server" (port 80)" Echo server" (port 7)" Client" Service request for" 128.2.194.242:7" (i.e., the echo server)" OS" Web server" (port 80)" Echo server" (port 7)" 9

Knowing What Port Number To Use Popular applicalons have well- known ports E.g., port 80 for Web and port 25 for e- mail See hfp://www.iana.org/assignments/port- numbers Well- known vs. ephemeral ports Server has a well- known port (e.g., port 80) Between 0 and 1023 (requires root to use) Client picks an unused ephemeral (i.e., temporary) port Between 1024 and 65535 Uniquely idenlfying traffic between the hosts Two IP addresses and two port numbers Underlying transport protocol (e.g., TCP or UDP) This is the 5- tuple I discussed last lecture 10

UNIX Socket API Socket interface Originally provided in Berkeley UNIX Later adopted by all popular operalng systems Simplifies porlng applicalons to different OSes In UNIX, everything is like a file All input is like reading a file All output is like wrilng a file File is represented by an integer file descriptor API implemented as system calls E.g., connect, read, write, close, 11

Puhng it All Together Server socket() bind() listen() accept() establish conneclon Client socket() connect() block read() send request write() process request write() send response read() 12

Client CreaLng a Socket: socket() CreaLng a socket int socket(int domain, int type, int protocol)! Returns a file descriptor (or handle) for the socket Originally designed to support any protocol suite Domain: protocol family PF_INET for the Internet (IPv4) Type: semanlcs of the communicalon SOCK_STREAM: reliable byte stream (TCP) SOCK_DGRAM: message- oriented service (UDP) Protocol: specific protocol UNSPEC: unspecified (PF_INET and SOCK_STREAM already implies TCP) 13

Client: Learning Server Address/Port Server typically known by name and service E.g., www.cnn.com and hfp Need to translate into IP address and port # E.g., 64.236.16.20 and 80 TranslaLng the server s name to an address struct hostent *gethostbyname(char *name)! Argument: host name (e.g., www.cnn.com ) Returns a structure that includes the host address IdenLfying the service s port number struct servent! *getservbyname(char *name, char *proto)! Arguments: service (e.g., kp ) and protocol (e.g., tcp ) StaLc config in/etc/services! 14

Client: ConnecLng Socket to the Server Client contacts the server to establish conneclon Associate the socket with the server address/port Acquire a local port number (assigned by the OS) Request conneclon to server, who hopefully accepts Establishing the conneclon int connect (int sockfd,! struct sockaddr *server_address,! socketlen_t addrlen)! Arguments: socket descriptor, server address, and address size Returns 0 on success, and - 1 if an error occurs 15

Client: Sending Data Sending data ssize_t write! (int sockfd, void *buf, size_t len)! Arguments: socket descriptor, pointer to buffer of data to send, and length of the buffer Returns the number of bytes wrifen, and - 1 on error 16

Client: Receiving Data Receiving data ssize_t read!!!(int sockfd, void *buf, size_t len)! Arguments: socket descriptor, pointer to buffer to place the data, size of the buffer Returns the number of characters read (where 0 implies end of file ), and - 1 on error Why do you need len? What happens if buf s size < len? Closing the socket int close(int sockfd)! 17

Server: Server Preparing its Socket Server creates a socket and binds address/port Server creates a socket, just like the client does Server associates the socket with the port number (and hopefully no other process is already using it!) Choose port 0 and let kernel assign ephemeral port Create a socket int socket (int domain,!!!!!! int type, int protocol)! Bind socket to the local address and port number int bind (int sockfd,!!!!struct sockaddr *my_addr,!!!!socklen_t addrlen)! Arguments: sockfd, server address, address length Returns 0 on success, and - 1 if an error occurs 18

Server: Allowing Clients to Wait Many client requests may arrive Server cannot handle them all at the same Lme Server could reject the requests, or let them wait Define how many conneclons can be pending int listen(int sockfd, int backlog)! Arguments: socket descriptor and acceptable backlog Returns a 0 on success, and - 1 on error What if too many clients arrive? Some requests don t get through The Internet makes no promises And the client can always try again 19

Server: AccepLng Client ConnecLon Now all the server can do is wait Waits for conneclon request to arrive Blocking unll the request arrives And then acceplng the new request Accept a new conneclon from a client int accept(int sockfd,!!struct sockaddr *addr,!!!socketlen_t *addrlen)! Arguments: sockfd, structure that will provide client address and port, and length of the structure Returns descriptor of socket for this new conneclon 20

Server: One Request at a Time? Serializing requests is inefficient Server can process just one request at a Lme All other clients must wait unll previous one is done What makes this inefficient? May need to Lme share the server machine Alternate between servicing different requests Do a lifle work on one request, then switch when you are wailng for some other resource (e.g., reading file from disk) Nonblocking I/O Or, use a different process/thread for each request Allow OS to share the CPU(s) across processes Or, some hybrid of these two approaches 21

Client and Server: Cleaning House Once the conneclon is open Both sides and read and write Two unidireclonal streams of data In praclce, client writes first, and server reads then server writes, and client reads, and so on Closing down the conneclon Either side can close the conneclon using the close() system call What about the data slll in flight Data in flight slll reaches the other end So, server can close() before client finishes reading 22

Wanna See Real Clients and Servers? Apache Web server Open source server first released in 1995 Name derives from a patchy server ;- ) Sokware available online at hfp://www.apache.org Mozilla Web browser hfp://www.mozilla.org/developer/ Sendmail hfp://www.sendmail.org/ BIND Domain Name System Client resolver and DNS server hfp://www.isc.org/index.pl?/sw/bind/ 23