Socket Interface 1 Introduction 11 Socket address formats 2 API 12 13

Slides:



Advertisements
Similar presentations
Networks: TCP/IP Socket Calls1 Elementary TCP Sockets Chapter 4 UNIX Network Programming Vol. 1, Second Ed. Stevens.
Advertisements

Tutorial 8 Socket Programming
1 Generic Transport Service Primitives Listen –notify Transport layer a call is expected Connect –establish Transport layer connection Send (or Write)
UDP: User Datagram Protocol. UDP: User Datagram Protocol [RFC 768] r “bare bones”, “best effort” transport protocol r connectionless: m no handshaking.
CS 311 – Lecture 18 Outline IPC via Sockets – Server side socket() bind() accept() listen() – Client side connect() Lecture 181CS Operating Systems.
© 2007 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.1 Computer Networks and Internets with Internet Applications, 4e By Douglas.
Socket Addresses. Domains Internet domains –familiar with these Unix domains –for processes communicating on the same hosts –not sure of widespread use.
CSE/EE 461 Getting Started with Networking. Basic Concepts  A PROCESS is an executing program somewhere.  Eg, “./a.out”  A MESSAGE contains information.
ISP – 9 th Recitation Socket programming – Client side.
1 Tutorial on Socket Programming Computer Networks - CSC 458 Department of Computer Science Yukun Zhu (Slides are mainly from Monia Ghobadi, and Amin Tootoonchian,
Basic Socket Programming TCP/IP overview. TCP interface Reference: –UNIX Network Programming, by Richard Stevens. –UNIX man page.
1 Programming with TCP/IP Ram Dantu. 2 Client Server Computing r Although the Internet provides a basic communication service, the protocol software cannot.
TCP Socket Programming. r An abstract interface provided to the application programmer  File descriptor, allows apps to read/write to the network r Allows.
Network Programming Tutorial #9 CPSC 261. A socket is one end of a virtual communication channel Provides network connectivity to any other socket anywhere.
Chapter 24 - Socket Interface Introduction API The Socket API Sockets and socket libraries Sockets and UNIX I/O The socket API Summary of socket system.
9/12/2015B.R1 Socket Abstraction and Interprocess Communication B.Ramamurthy CSE421.
 Wind River Systems, Inc Chapter - 13 Network Programming.
Chapter 2 Applications and Layered Architectures Sockets.
The Socket Interface Chapter 21. Application Program Interface (API) Interface used between application programs and TCP/IP protocols Interface used between.
The Socket Interface Chapter 22. Introduction This chapter reviews one example of an Application Program Interface (API) which is the interface between.
Windows Operating System Internals - by David A. Solomon and Mark E. Russinovich with Andreas Polze Unit OS A: Windows Networking A.2. Windows Sockets.
Outline Socket programming with Windows OSSocket programming with Windows OS C++ UDPSocket classC++ UDPSocket class Socket programming with Windows OSSocket.
1 Computer Networks An Introduction to Computer Networks University of Tehran Dept. of EE and Computer Engineering By: Dr. Nasser Yazdani Lecture 3: Sockets.
TELE202 Lecture 15 Socket programming 1 Lecturer Dr Z. Huang Overview ¥Last Lecture »TCP/UDP (2) »Source: chapter 17 ¥This Lecture »Socket programming.
Introduction to Socket
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 3.1 Internet Applications Ch. 28,… (Client-Server Concept, Use of Protocol Ports, Socket API)
CSE/EE 461 Getting Started with Networking. 2 Basic Concepts A PROCESS is an executing program somewhere. –Eg, “./a.out” A MESSAGE contains information.
Chapter 27 Socket API Interface The interface between an application program and the communication protocols in an operating system is known as the Application.
Socket Programming Tutorial Department of Computer Science Southern Illinois University Edwardsville Fall, 2015 Dr. Hiroshi Fujinoki
Socket Programming Lab 1 1CS Computer Networks.
1 Sockets Programming Socket to me!. 2 Network Application Programming Interface (API) The services provided by the operating system that provide the.
CS 6401 Introduction to Computer Networks 09/21/2010 Outline - UNIX sockets - A simple client-server program - Project 1 - LAN bridges and learning.
Part 4: Network Applications Client-server interaction, example applications.
2: Application Layer1 Chapter 2: Application layer r 2.1 Principles of network applications r 2.2 Web and HTTP r 2.3 FTP r 2.4 Electronic Mail  SMTP,
CSCI 330 UNIX and Network Programming Unit XIV: User Datagram Protocol.
UNIX Sockets Outline UNIX sockets CS 640.
1 Spring Semester 2008, Dept. of Computer Science, Technion Internet Networking recitation #7 Socket Programming.
Lecture 15 Socket Programming CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger.
The Socket Interface Client and server use the transport protocol to communicate. When it interacts with protocol, an application must specify :whether.
1 Socket Interface. 2 Client-Server Architecture The client is the one who speaks first Typical client-server situations  Client and server on the same.
1 Socket Interface. 2 Basic Sockets API Review Socket Library TCPUDP IP EthernetPPP ARP DHCP, Mail, WWW, TELNET, FTP... Network cardCom Layer 4 / Transport.
Socket Abstraction and Interprocess Communication
Sockets and Beginning Network Programming
Network Programming CSC- 341
Week 13 - Friday CS222.
Socket Programming in C
Tutorial on Socket Programming
Interprocess Communication
CSI 4118 – UNIVERSITY OF OTTAWA
Interacting With Protocol Software
Transport layer API: Socket Programming
UNIX Sockets Outline Homework #1 posted by end of day
Socket Abstraction and Interprocess Communication
The Socket Interface Client and server use the transport protocol to communicate. When it interacts with protocol, an application must specify :whether.
Socket Abstraction and Interprocess Communication
Socket Abstraction and Inter-process Communication
Socket Abstraction and Interprocess Communication
Interprocess Communication
Socket Abstraction and Interprocess Communication
Chapter 3 Socket API © Bobby Hoggard, Department of Computer Science, East Carolina University These slides may not be used or duplicated without permission.
Socket Abstraction and Interprocess Communication
Socket Abstraction and Interprocess Communication
Socket Abstraction and Inter-process Communication
Sockets Programming Socket to me!.
Socket Abstraction and Inter-process Communication
Sockets Programming Socket to me!.
Internet Networking recitation #8
Sockets.
Today’s topic: Basic TCP API
CSI 4118 – UNIVERSITY OF OTTAWA
Presentation transcript:

Socket Interface 1 Introduction 11 Socket address formats 2 API 12 13 listen 13 accept 3 The Socket API 14 connect 4 Sockets and socket libraries 15 send 5 Sockets and UNIX I/O 16 sendto, sendmsg 6 The socket API 17 recv 7 Summary of socket system calls 18 recvfrom, recvmsg 8 socket 19 Other procedures 9 close 20 Sockets and processes 10 bind 21 Summary

Introduction The socket is one form of interface between application programs and protocol software Widely available - program portability Used by both clients and servers Extension to UNIX file I/O paradigm

API Application interactions with protocol software: Passive listen or active open Protocol to use IP address and port number Interface to protocol is call Application Program Interface (API) Defined by programming/operating system Includes collection of procedures for application program

The Socket API Protocols do not typically specify API API defined by programming system Allows greatest flexibility - compatibility with different programming systems Socket API is a specific protocol API Originated with Berkeley BSD UNIX Now available on Windows 95 and Windows NT, Solaris, etc. Not defined as TCP/IP standard; de facto standard

Sockets and socket libraries BSD UNIX includes sockets as system calls Other vendors (mostly UNIX) have followed suit Some systems have different API Adding sockets would require changing OS Added library procedures - socket library - instead Adds layer of software between application and operating system Enhances portability May hide native API altogether

Sockets and UNIX I/O Developed as extension to UNIX I/O system Uses same file descriptor address space (small integers) Based on open-read-write-close paradigm open - prepare a file for access read/write - access contents of file close - gracefully terminate use of file Open returns a file descriptor, which is used to identify the file to read/write/close

The socket API Socket programming more complex than file I/O Requires more parameters Addresses Protocol port numbers Type of protocol New semantics Two techniques Add parameters to existing I/O system calls Create new system calls Sockets use a collection of new system calls

Summary of socket system calls socket - create a new socket close - terminate use of a socket bind - attach a network address to a socket listen - wait for incoming messages accept - begin using incoming connection connect - make connection to remote host send - transmit data through active connection recv - receive data through active connection

descriptor = socket(protofamily, type, protocol) Returns socket descriptor used in subsequent calls protofamily selects protocol family; e.g.: PF_INET - Internet protocols PF_APPLETALK - AppleTalk protocols type selects type of communication SOCK_DGRAM - connectionless SOCK_STREAM - connection-oriented protocol specifies protocol within protocol family IPPROTO_TCP - selects TCP IPPROTO_UDP - selects UDP

close close(descriptor) Terminates use of socket descriptor descriptor contains descriptor of socket to be closed

bind(socket, localaddr, address) Initially, socket has no addresses attached bind selects either local, remote or both addresses server binds local port number for incoming messages client binds remote address and port number to contact server

Socket address formats Because sockets can be used for any protocols, address format is generic: struct sockaddr { u_char sa_len; /* total length of address */ u_char sa_family; /* family of the address */ char sa_data[14]; /* address */ } For IP protocols, sa_data hold IP address and port number: struct sockaddr_in { u_char sin_len; /* total length of address */ u_char sin_family; /* family of the address */ u_short sin_port; /* protocol port number */ struct in_addr sin_addr; /* IP address */ char sin_zero[8] /* unused */ First two fields match generic sockaddr structure Remainder are specific to IP protocols INADDR_ANY interpreted to mean "any" IP address Socket address formats

listen(socket, queuesize) Server uses listen to wait for incoming connections socket identifies socket through which connections will arrive (address) New connection requests may arrive while server processes previous request Operating system can hold requests on queue queuesize sets upper limit on outstanding requests

accept(socket, caddress, caddresslen) Server uses accept to accept the next connection request accept call blocks until connection request arrives Returns new socket with server's end of new connection Old socket remains unchanged and continues to field incoming requests caddress returns struct sockaddr client address; format depends on address family of socket caddresslen returns length of address

connect(socket, saddress, saddresslen) Client uses connect to establish connection to server Blocks until connection completed (accepted) socket holds descriptor of socket to use saddress is a struct sockaddr that identifies server saddresslen gives length of saddress Usually used with connection-oriented transport protocol Can be used with connectionless protocol Marks local socket with server address Implicitly identifies server for subsequent messages

send(socket, data, length, flags) Used to send data through a connected socket socket identifies socket data points to data to be sent length gives length of data (in bytes) flags indicate special options

sendto(socket, data, length, flags, destaddress, addresslen) sendmsg(socket, msgstruct, flags) Used for unconnected sockets by explicitly specifying destination sendto adds additional parameters: destaddress - struct sockaddr destination address addresslen - length of destaddress sendmsg combines list of parameters into single structure: struct msgstruct { struct sockaddr *m_addr; /* ptr to destination address */ struct datavec *m_vec; /* pointer to message vector */ int m_dvlength; /* num. of items in vector */ struct access *m_rights; /* ptr to access rights list */ int m_alength; /* num. of items in list */ } sendto, sendmsg

recv(socket, buffer, length, flags) Used to receive incoming data through connected socket socket identifies the socket Data copied into buffer At most length bytes will be recved flags give special options Returns number of bytes actually recved 0 implies connection closed -1 implies error

recvfrom, recvmsg recvfrom(socket, buffer, length, flags, sndraddress, addresslen) recvmsg(socket, msgstruct, flags) Like sendto and sendmsg (in reverse!) Address of source copied into sndraddress Length of address in addresslen recvmsg uses msgstruct for parameters

Other procedures getpeername - address of other end of connection getsockname - current address bound to socket setsockopt - set socket options

Sockets and processes Like file descriptors, sockets are inherited by child processes Socket disappears when all processes have closed it Servers use socket inheritance to pass incoming connections to slave server processes

Summary Socket API is de facto standard Originally developed for BSD UNIX Copied to many other systems Sockets are an extension of the UNIX file I/O system Use same descriptor addresses Can (but typically don't) use same system calls Many specific system calls for sockets