SOCKETS Lecture #3. The Socket Interface Funded by ARPA (Advanced Research Projects Agency) in 1980. Developed at UC Berkeley Objective: to transport.

Slides:



Advertisements
Similar presentations
Introduction to Sockets Jan Why do we need sockets? Provides an abstraction for interprocess communication.
Advertisements

Taekyung Kim 0x410 ~ 0x International Standards Organization (ISO) is a multinational body dedicated to worldwide agreement on international.
Data Communications and Networking (Third Edition)
CS335 Networking & Network Administration Tuesday, May 25, 2010.
Networks: TCP/IP Socket Calls1 Elementary TCP Sockets Chapter 4 UNIX Network Programming Vol. 1, Second Ed. Stevens.
Generic Transport Service Primitives Listen –notify Transport layer a call is expected Connect –establish Transport layer connection Send (or Write) Receive.
Socket Programming.
Socket Programming: a Primer Socket to me!. Feb. 23, 2001EE122, UCB2 Why does one need sockets? application network protocol sockets network.
EECS122 Communications Networks Socket Programming January 30th, 2003 Jörn Altmann.
1 Socket Interfaces Professor Jinhua Guo CIS527 Fall 2003.
Client Design. Issues Server Identification Setting up a socket on client side TCP –Reading and writing with a socket –Closing a socket UDP –Reading and.
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)
Programming with Berkeley Sockets Presented by Chris GauthierDickey Written by Daniel Stutzbach (I think!) for CIS 432/532 Useful References: ● man pages.
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.
Socket Addresses. Domains Internet domains –familiar with these Unix domains –for processes communicating on the same hosts –not sure of widespread use.
Client Server Model and Software Design TCP/IP allows a programmer to establish communication between two application and to pass data back and forth.
Chapter 26 Client Server Interaction Communication across a computer network requires a pair of application programs to cooperate. One application on one.
1 Tutorial on Socket Programming Computer Networks - CSC 458 Department of Computer Science Yukun Zhu (Slides are mainly from Monia Ghobadi, and Amin Tootoonchian,
Client Software Design Objectives: Understand principles of C/S design, with focus on clients Review Windows implementations of Socket functions.
Sockets CIS 370 Fall 2009, UMassD. Introduction  Sockets provide a simple programming interface which is consistent for processes on the same machine.
UNIX Socket Programming CS 6378
TCP Socket Programming. r An abstract interface provided to the application programmer  File descriptor, allows apps to read/write to the network r Allows.
ECE 4110 – Internetwork Programming Client-Server Model.
TCP/IP Protocol Stack IP Device Drivers TCPUDP Application Sockets (Gate to network) TCP: –Establish connection –Maintain connection during the communication.
Socket Programming. Introduction Sockets are a protocol independent method of creating a connection between processes. Sockets can be either – Connection.
Chapter 17 Networking Dave Bremer Otago Polytechnic, N.Z. ©2008, Prentice Hall Operating Systems: Internals and Design Principles, 6/E William Stallings.
Sirak Kaewjamnong Computer Network Systems
Server Sockets: A server socket listens on a given port Many different clients may be connecting to that port Ideally, you would like a separate file descriptor.
CSTP FS01CS423 (cotter)1 Protocols 2 References: RFC’s 791, 793, 768, 826.
The Application Layer Application Services (Telnet, FTP, , WWW) Reliable Stream Transport (TCP) Connectionless Packet Delivery Service (IP) Unreliable.
 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.
Networking Tutorial Special Interest Group for Software Engineering Luke Rajlich.
CPSC 441 TUTORIAL – FEB 13, 2012 TA: RUITNG ZHOU UDP REVIEW.
1 Computer Networks An Introduction to Computer Networks University of Tehran Dept. of EE and Computer Engineering By: Dr. Nasser Yazdani Lecture 3: Sockets.
The Sockets Library and Concepts Rudra Dutta CSC Spring 2007, Section 001.
TELE202 Lecture 15 Socket programming 1 Lecturer Dr Z. Huang Overview ¥Last Lecture »TCP/UDP (2) »Source: chapter 17 ¥This Lecture »Socket programming.
UNIX Sockets COS 461 Precept 1. Socket and Process Communication The interface that the OS provides to its networking subsystem application layer transport.
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)
Socket Programming Lab 1 1CS Computer Networks.
Process to process communication over network connections Includes references to Comer and Stevens Internetworking with TCP/IP vol 3 Client-server programming.
1 Sockets Programming Socket to me!. 2 Network Application Programming Interface (API) The services provided by the operating system that provide the.
Sockets Socket = abstraction of the port concept: –Application programs request that the operating system create a socket when one is needed –O.S. returns.
Part 4: Network Applications Client-server interaction, example applications.
Socket Programming.
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,
Berkeley Socket Abstraction
2: Application Layer 1 Socket Programming UNIX Network Programming, Socket Programming Tutorial:
CSCI 330 UNIX and Network Programming Unit XIV: User Datagram Protocol.
Socket Programming. Computer Science, FSU2 Interprocess Communication Within a single system – Pipes, FIFOs – Message Queues – Semaphores, Shared Memory.
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.
Client-server communication Prof. Wenwen Li School of Geographical Sciences and Urban Planning 5644 Coor Hall
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.
Socket Programming(1/2). Outline  1. Introduction to Network Programming  2. Network Architecture – Client/Server Model  3. TCP Socket Programming.
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 PROGRAMMING Presented By : Divya Sharma.
Socket Interface 1 Introduction 11 Socket address formats 2 API 12 13
Tutorial on Socket Programming
Interacting With Protocol Software
Transport layer API: Socket Programming
Socket Programming.
Socket Programming(1/2)
Sockets Programming Socket to me!.
Sockets Programming Socket to me!.
Presentation transcript:

SOCKETS Lecture #3

The Socket Interface Funded by ARPA (Advanced Research Projects Agency) in Developed at UC Berkeley Objective: to transport TCP/IP software to UNIX The socket interface has become a de facto standard.

Approach Define functions that support network communications in general, and use parameters to make TCP/IP communication a special case. Socket calls refer to all TCP/IP protocols as a single protocol family.

TCP/IP provides peer-to-peer communication. Is a protocol that provides basic mechanisms to transfer data provides connectionless and connection- oriented servers.

Concurrency Main() { int I; fork(); for(I=0; I<5; I++) { printf(“I = %d\n”, I); fflush(stdout); } exit(0); }

Fork (Cont’d) main() { int pid; pid = fork(); if ( pid == 0 ) printf(“The child process\n”); else printf(“The parent process\n”); exit(0); }

Basic I/O Functions in UNIX Open close read write lseek ioctl

Using I/O in UNIX int desc;... desc = open(“file”, O_RDWR, 0); read(desc, buffer, 128); … close(desc);

Using UNIX I/O with TCP/IP They extended the conventional UNIX I/O facilities It became possible to use file descriptors for network communication Extended the read and write system calls so they work with the new network descriptors.

Descriptor Table Internal data structure for file 0

Internal data structure for file 0 Family: PF_INET... Service: SOCK_STREAM Local IP: Remote IP: Local Port: Remote Port:

Passive/Active Socket A passive socket is used by a server to wait for an incoming connection. An active socket is used by a client to initiate a connection.

Sockets When a socket is created it does not contain information about how it will be used. TCP/IP protocols define a communication endpoint to consist of an IP address and a protocol port number.

Socket Functions socket: create a descriptor for use in network communication. connect: connect to a remote peer (used by client) write: send outgoing data across a connection. read: acquire incoming data from a connection.

Socket Functions (Cont’d) close: terminate communication and deallocate a descriptor. bind: bind a local IP address and protocol number to a socket. listen: place the socket in passive mode and set the number of incoming TCP connections the system will enqueue. accept: accept the next incoming connection (by server).

Data Conversion Functions The functions htons, ntohs, htonl, and ntohl are used to convert binary integers between the host’s native byte order and the network standard byte order. This makes the source code portable to any machine, independent of the the native byte order

socket() bind() listen() accept() read() write() procees request get a blocked client Server Process TCPUDP socket() connect() write() read() Client Process socket() bind() sendto() recvfrom() Client Process socket() bind() recvfrom() sendto() Server Process get a blocked client process request

TCP vs. UDP TCP (Transmission Control Protocol –Connection-oriented –Reliability in delivery of messages –Splitting messages into datagrams –keep track of order (or sequence) –Use checksums for detecting errors

TCP vs. UDP (Cont’d) UDP (User Datagram Protocols) –Connectionless –No attempt to fragment messages –No reassembly and synchronization –In case of error, message is retransmitted –No acknowledgment

Selecting UDP Remote procedures are idempotent Server and client messages fit completely within a packet. The server handles multiple clients (UDP is stateless)

Selecting TCP Procedures are not idempotent Reliability is a must Messages exceed UDP packet size

OSI Layers vs. TCP/IP Network Hardware Interface IP TCP UDP User Application 5-7. Session 4. Transport 3. Network 1-2. Data Link/ Physical

Client Architecture Simpler than servers Most clients do not explicitly handle concurrent interactions with multiple servers. Most client software executes as a conventional program. Clients, unlike servers, do not require special privileged ports. Most clients rely on OS for security.

Socket Address Structure struct sockaddr_in { shortsin_family; u_short sin_port; struct in_addr sin_addr; charsin_zero[8]; };

Domain Name Structure struct hostent { char *h_name;/* official name of host */ char **h_aliases;/* host’s alias names */ int h_addrtype;/* address type */ char **h_addr_list; /*list of addresses from name server */ };

Example: Char *host = “eve.kean.edu”; struct hostent *hp; … hp = gethostbyname(host); “inet_addr()” takes an ASCII string that contains a dotted decimal address and returns the equivalent IP address in binary.

Service Structure struct servent { char *s_name;/* service name */ char **s_aliases;/* alias list */ int s_port;/* port number */ char *s_proto;/* protocol to use */ };

Example: struct servent *sp;.. sp = getservbyname(“smtp”, “”tcp”); sp->s_port has the port number.

The Protocol Structure struct protoent { char *p_name;/* official protocol name */ char **p_aliases;/* allowed aliases */ int p_proto;/* official protocol number */ }; Example: struct protent *pp; pp = getprotobyname(“udp”);

ACCEPT accept(s, address, len) Used by servers to accept the next incoming connection. Returns the socket descriptor of the new socket. Used only with TCP

s, from, to: socket descriptor address: pointer to the struct sockaddr len, fromlen, tolen: size of sockaddr name: character string protocol: character string Qlen: integer buffer: character array flags: integer

BIND Bind( s, address, len ) binds a local IP and protocol number to a socket. Used by servers primarily Returns 0 if successful, or -1 in case of error.

CLOSE close(s) Terminates communication and deallocates the socket. Returns 0 or -1

CONNECT connect( s, address, len ) Used to specify the remote end point address Used with TCP and UDP Returns 0 or -1

GETHOSTBYNAME gethostbyname( name ) translates host name to an IP address. Returns a pointer to a hostent structure, if successful; otherwise it returns 0

GETPROTOBYNAME getprotobyname( name ) Translates protocol’s name to its official integer value. Returns a pointer to the protoent structure; otherwise it returns 0.

LISTEN listen( s, Qlen) It puts the socket in a receiving mode to accept incoming requests. It also sets a limit on the queue size for incoming connection requests. Returns 0 or -1.

GETSERVBYNAME getservbyname( name, protocol ) Used to map a service name to a protocol port number. Returns a pointer to a servent structure, if successful; otherwise it returns 0.

READ read( s, buffer, len) Used to get input from a socket. Returns 0 in case of error, or the number of bytes read in case of success.

RECV recv( s, buffer, len, flags ) gets the next incoming message from a socket. Flags Control bits that specify whether to receive out-of-band data and whether to look ahead for messages. Returns the number of bytes in the message, or -1 in case of error.

RECVFROM recvfrom(s, buffer, len, flags, from,fromlen) Gets the next message that arrives at a socket and records the sender’s address. Returns the number of bytes in the message, or -1 in case of error.

SELECT select(numfds, refds, wrfds, exfds, time); Provides asynchronous I/O by permitting a single process to wait for the first of any file descriptors in a specified set to become ready. The caller can also specify a maximum timeout for the wait.

SELECT (Cont’d) numfds: number of file descriptors in set refds: address of file descriptors for input wrfds: address of file descriptors for output exfds: address of file descriptors for exceptions time: maximum time to wait (or zero) Returns the number of ready file descriptors, 0 if time limit reached, or -1 for error.

SEND send( s, msg, len, flags) To transfer a message to another machine. Returns the number of characters sent, or -1 in case of error.

SENDTO sendto( s, msg, len, flags, to, tolen) To send a message using the destination structure to. Returns the number of bytes sent, or -1 in case of error.

SOCKET socket(family, type, protocol ) To create a socket. Returns the integer descriptor for the socket, or -1 in case of error.

WRITE write( s, buffer, len) write(Allows an application to transfer data to a remote machine. Returns the number of bytes transferred or - 1 in case of error.

References “Internetworking with TCP/IP, VOL III, Client-Server Programming and Applications”, D. Comer and D. Stevens, Prentice Hall