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

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

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

TCP: Three-way handshake

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

Lecture 5 Overview! Last Lecture! This Lecture! Next Lecture! I/O multiplexing! Source: Chapter 6 of Stevens book!

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

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

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

Socket Programming for TCP and UDP

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

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

Elementary TCP Sockets

CSE 124 Discussion Section Sockets Programming 10/10/17

UNIT IV- SOCKETS Part A

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

Group-A Assignment No. 6

Introduction to Socket Programming

STUDY OF SOCKET PROGRAMMING

Socket Programming TCP UDP

Tutorial on Socket Programming

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

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

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

Programming with TCP/IP. Ram Dantu

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

Communication. Sockets (Haviland Ch. 10)

CSC209H Lecture 9. Dan Zingaro. March 11, 2015

Network Communication

EEC-484/584 Computer Networks

CS 640: Computer Networking

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

Unix Network Programming

Sockets. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

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

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

Unix Network Programming Chapter 4. Elementary TCP Sockets 광운대학교컴퓨터과학과 정보통신연구실 석사과정안중현

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

CLIENT-SIDE PROGRAMMING

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

Hyo-bong Son Computer Systems Laboratory Sungkyunkwan University

Network programming(i) Lenuta Alboaie

Socket Programming(2/2)

UNIX Network Programming. Overview of Socket API Network Programming Basics

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

Introduction for SPI mapping Service Discovery Interoperability Testing. 20, Sep PWG Fumio Nagasaka

CS 3516: Computer Networks

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

System Programming. Sockets

UNIX Sockets. COS 461 Precept 1

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

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

Systems software design NETWORK COMMUNICATIONS & RPC SYSTEMS

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

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

CS321: Computer Networks Introduction to Application Layer

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

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

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

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

Agenda. Before we start: Assignment #1. Routing in a wide area network. Protocols more concepts. Internetworking. Congestion control

Network programming(ii) Lenuta Alboaie

Network Socket Programming - 3 BUPT/QMUL

Sockets 15H2. Inshik Song

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

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

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

Network Socket Programming - 3 BUPT/QMUL

The User Datagram Protocol

Introduction to Socket Programming

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

CS321: Computer Networks Socket Programming

Computer Networks Prof. Ashok K. Agrawala

A. Basic Function Calls for Network Communications

Client Server Computing

A Client-Server Exchange

CSE 333 SECTION 8. Sockets, Network Programming

UDP CONNECT TO A SERVER

CSE 333 Section 8 - Client-Side Networking

CSE 333 SECTION 7. Client-Side Network Programming

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

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

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

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

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

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

UNIT 1 TCP/IP PROGRAMMING CONCEPTS

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

Communication Networks ( ) / Fall 2013 The Blavatnik School of Computer Science, Tel-Aviv University

Internet applications

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

CS4700/CS5700 Fundamentals of Computer Networking

Content 1. SDK Library Overview API Library Introduction API Data Structure HAL Driver Function Type LIB

Topics for this Week

SOCKETS: INTRODUCTION

The Berkeley Sockets API. Networked Systems Architecture 3 Lecture 4

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

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

What s an API? Do we need standardization?

Transcription:

Outline Distributed Computer Systems Socket basics Socket details (TCP and UDP) Socket options Final notes Sockets Socket Basics An end-point for a IP network connection what the application layer plugs into programmer cares about Application Programming Interface (API) End point determined by two things: Host address: IP address is Network Layer Port number: is Trans Layer Two end-points determine a connection: socket pair ex: 206.62.226.35,p21 + 198.69.10.2,p1500 ex: 206.62.226.35,p21 + 198.69.10.2,p1499 Ports Numbers (vary by OS): 0-1023 reserved, must be root 1024-5000 ephemeral however, many systems allow > 3977 s + (50,000 is correct number) Well-known, reserved services (see /etc/services in Unix): ftp 21/tcp telnet 23/tcp finger 79/tcp snmp 161/udp Sockets and the OS User Application Socket Operating System Trans Layer User sees descriptor, integer index like: FILE *, or file index from open() returned by call (more later) Trans Layer UDP: User Datagram Protocol no acknowledgements no retransmissions out of order, duplicates possible connectionless games, streaming audio and video, dns TCP: Transmission Control Protocol reliable (in order, all arrive, no duplicates) flow control connection Web browsing, telnet, file transfer Project 1 1

Outline Socket basics Socket details (TCP and UDP) Socket options Final notes Socket Details Outline Unix Network Programming, W. Richard Stevens, 2nd edition, 1998, Prentice Hall Code is very similar for Windows Addresses and Sockets TCP client-server (talk-tcp, listen-tcp) UDP client-server (talk-udp, listen-udp) Misc stuff setsockopt(), getsockopt() fcntl() Addresses and Sockets Structure to hold address information Functions pass address from user to OS Functions pass address from OS to user Socket Address Structure struct in_addr { in_addr_t s_addr; /* 32-bit IPv4 addresses */ }; struct sockaddr_in { unit8_t sin_len; /* length of structure */ sa_family_t sin_family; /* AF_INET */ in t sin_; /* TCP/UDP Port num */ struct in_addr sin_addr; /* IPv4 address (above) */ char sin_zero[8]; /* unused */ } Are also generic and IPv6 socket structures TCP - (Block until connection) Handshake Data (request) End-of-File int socket(int family, int type, int protocol); Create a socket, giving access to trans layer service. family is one of AF_INET (IPv4), AF_INET6 (IPv6), AF_LOCAL (local Unix), AF_ROUTE (access to routing tables), AF_KEY (new, for encryption) type is one of SOCK_STREAM (TCP), SOCK_DGRAM (UDP) SOCK_RAW (for special IP packets, PING, etc. Must be root) + setuid bit (-rws--x--x root 1997 /sbin/ping*) protocol is 0 (used for some raw socket options) upon success returns socket descriptor Integer, like file descriptor Return -1 if failure 2

int bind(int sockfd, const struct sockaddr *myaddr, socklen_t addrlen); Assign a local protocol address ( name ) to a socket. myaddr is a pointer to address struct with: number and IP address if is 0, then host will pick ephemeral + not usually for server (exception RPC -map) IP address!= INADDR_ANY (unless multiple nics) addrlen is length of structure returns 0 if ok, -1 on error EADDRINUSE ( Address already in use ) int listen(int sockfd, int backlog); Change socket state for TCP server. backlog is maximum number of incomplete connections historically 5 rarely above 15 on a even moderate Web server! Sockets default to active (for a client) change to passive so OS will accept connection int accept(int sockfd, struct sockaddr cliaddr, socklen_t *addrlen); Return next completed connection. cliaddr and addrlen return protocol address from client returns brand new descriptor, created by OS note, if create new process or thread, can create concurrent server int close(int sockfd); Close socket for use. closes socket for reading/writing returns (doesn t block) attempts to send any unsent data socket option SO_LINGER + block until data sent + or discard any remaining data returns -1 if error TCP - (Block until connection) Handshake Data (request) End-of-File int connect(int sockfd, const struct sockaddr *servaddr, socklen_t addrlen); Connect to server. servaddr is a pointer to a structure with: number and IP address must be specified (unlike ) addrlen is length of structure client doesn t need OS will pick ephemeral returns socket descriptor if ok, -1 on error 3

Sending and Receiving int recv(int sockfd, void *buff, size_t mbytes, int flags); int send(int sockfd, void *buff, size_t mbytes, int flags); Same as read() and write() but for flags MSG_DONTWAIT (this send non-blocking) MSG_OOB (out of band data, 1 byte sent ahead) MSG_PEEK (look, but don t remove) MSG_WAITALL (don t give me less than max) MSG_DONTROUTE (bypass routing table) UDP - (Block until receive datagram) Data (request) -No handshake - No simultaneous close - No fork() for concurrent servers! Sending and Receiving int recvfrom(int sockfd, void *buff, size_t mbytes, int flags, struct sockaddr *from, socklen_t *addrlen); int sendto(int sockfd, void *buff, size_t mbytes, int flags, const struct sockaddr *to, socklen_t addrlen); Same as and but for addr recvfrom fills in address of where packet came from sendto requires address of where sending packet to with UDP Record address and of peer datagrams to/from others are not allowed does not do three way handshake, or connection connect a misnomer, here. Should be setpeername() Use instead of Use instead of Can change connect or unconnect by repeating call (Can do similar with on receiver) Why use connected UDP? Socket Options (General) Send two datagrams unconnected: output first dgram unconnect the socket ouput second dgram unconnect the socket Send two datagrams connected: output first dgram ouput second dgram setsockopt(), getsockopt() SO_LINGER upon close, discard data or block until sent SO_RCVBUF, SO_SNDBUF change buffer sizes for TCP is pipeline, for UDP is discard SO_RCVLOWAT, SO_SNDLOWAT how much data before readable via select() SO_RCVTIMEO, SO_SNDTIMEO timeouts 4

Socket Options (TCP) TCP_KEEPALIVE idle time before close (2 hours, default) TCP_MAXRT set timeout value TCP_NODELAY disable Nagle Algorithm fcntl() File control but used for sockets, too Signal driven sockets Set socket owner Get socket owner Set socket non-blocking flags = fcntl(sockfd, F_GETFL, 0); flags = O_NONBLOCK; fcntl(sockfd, F_SETFL, flags); Beware not getting flags before setting! Concurrent s Text segment sock = /* setup socket */ while (1) { newsock = accept(sock) fork() if child read(newsock) until exit } Parent int sock; int newsock; Child int sock; int newsock; Close sock in child, newsock in parent Reference count for socket descriptor Project 3: Distributed Shell Distributed Shell / Non-interactive command line args get-opt.c Uses TCP sockets listen.c and talk.c Security password (1) connect (2) ls (3) fork() and exec() (4) data 5