Socket Abstraction and Inter-process Communication

Slides:



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

Computer Net Lab/Praktikum Datenverarbeitung 2 1 Overview Sockets Sockets in C Sockets in Delphi.
Socket Programming.
Sockets Basics Conectionless Protocol. Today IPC Sockets Basic functions Handed code Q & A.
Windows Sockets Purpose Windows Sockets 2 (Winsock) enables programmers to create advanced internet, intranet, and other network-capable applications to.
1 Socket Interfaces Professor Jinhua Guo CIS527 Fall 2003.
Tutorial 8 Socket Programming
Programming with Berkeley Sockets Presented by Chris GauthierDickey Written by Daniel Stutzbach (I think!) for CIS 432/532 Useful References: ● man pages.
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.
Sockets CIS 370 Fall 2009, UMassD. Introduction  Sockets provide a simple programming interface which is consistent for processes on the same machine.
ECE 4110 – Internetwork Programming Client-Server Model.
Sockets and intro to IO multiplexing. Goals We are going to study sockets programming as means to introduce IO multiplexing problem. We will revisit socket.
TCP/IP Protocol Stack IP Device Drivers TCPUDP Application Sockets (Gate to network) TCP: –Establish connection –Maintain connection during the communication.
Network Programming Tutorial #9 CPSC 261. A socket is one end of a virtual communication channel Provides network connectivity to any other socket anywhere.
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.
9/12/2015B.R1 Socket Abstraction and Interprocess Communication B.Ramamurthy CSE421.
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.
 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.
Remote Shell CS230 Project #4 Assigned : Due date :
CS 158A1 1.4 Implementing Network Software Phenomenal success of the Internet: – Computer # connected doubled every year since 1981, now approaching 200.
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.
Distributed Computing A Programmer’s Perspective.
TELE202 Lecture 15 Socket programming 1 Lecturer Dr Z. Huang Overview ¥Last Lecture »TCP/UDP (2) »Source: chapter 17 ¥This Lecture »Socket programming.
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 Lab 1 1CS Computer Networks.
Socket Programming Introduction. Socket Definition A network socket is one endpoint in a two-way communication flow between two programs running over.
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.
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,
S OCKET P ROGRAMMING IN C Professor: Dr. Shu-Ching Chen TA: HsinYu Ha.
S OCKET P ROGRAMMING IN C Professor: Dr. Shu-Ching Chen TA: Hsin-Yu Ha.
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.
UNIX Sockets Outline UNIX sockets CS 640.
Inter-Process Communication 9.1 Unix Sockets You may regard a socket as being a communication endpoint. –For two processes to communicate, both must create.
1 Spring Semester 2008, Dept. of Computer Science, Technion Internet Networking recitation #7 Socket Programming.
Socket Programming in C CS587x Lecture 3 Department of Computer Science Iowa State University.
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 PROGRAMMING Presented By : Divya Sharma.
Socket Abstraction and Interprocess Communication
CSCE 313 Network Socket MP8 DUE: FRI MAY 5, 2017
Sockets and Beginning Network Programming
CS 1652 Jack Lange University of Pittsburgh
Socket Programming in C
Socket Interface 1 Introduction 11 Socket address formats 2 API 12 13
Interprocess Communication
Transport layer API: Socket Programming
UNIX Sockets Outline Homework #1 posted by end of day
Socket Abstraction and Interprocess Communication
Socket Abstraction and Interprocess Communication
Socket Abstraction and Inter-process Communication
Socket Abstraction and Interprocess Communication
Interprocess Communication
Socket Abstraction and Interprocess Communication
Socket Abstraction and Interprocess Communication
Socket Abstraction and Interprocess Communication
Socket Abstraction and Inter-process Communication
Internet Networking recitation #8
Sockets.
Presentation transcript:

Socket Abstraction and Inter-process Communication B.Ramamurthy CSE421 4/19/2019 B.R

Communication Mechanisms Pipes (process level) Sockets (OS level) Distributed System Methods Remote Procedure Call- RPC Remote Method Invocation (Programming language level) Other communication paradigms 4/19/2019 B.R

Introduction Typical applications today consist of many cooperating processes either on the same host or on different hosts. For example, consider a client-server application. How to share (large amounts of ) data? Share files? How to avoid contention? What kind of system support is available? We want a general mechanism that will work for processes irrespective of their location and across address spaces. 4/19/2019 B.R

Purposes of communication Data transfer Sharing data Event notification Process control (invoke methods, send messages) 4/19/2019 B.R

Communication using sockets What if wanted to communicate between processes that have no common ancestor? IPC for processes that are not necessarily on the same host? Means of network IO? Answer: sockets Lets study socket: architecture, API, usage Architecture: names, types, ports, addresses and domains 4/19/2019 B.R

Sockets Socket is an abstraction for an end point of communication that can be manipulated with a file descriptor. It is an abstract object from which messages are sent and received. Sockets are created within a communication domain just as files are created within a file system. A communication domain is an abstraction introduced to bundle common properties of processes communicating through sockets. Example: UNIX domain, internet domain. 4/19/2019 B.R

Sockets and ports message agreed port any port socket Internet address = 138.37.88.249 Internet address = 138.37.94.248 other ports client server 4/19/2019 B.R

Sockets and Addresses IP address and port number. About 216 ports are available for use by user processes. UDP and TCP abstraction of the above is a socket. Socket is associated with a protocol. IPC is transmitting a message between a socket in one process to a socket in another process. Messages sent to particular IP and port# can be received by the process whose socket is associated with that IP and port#. Processes cannot share ports with other processes within the computer. Can receive messages on diff ports. 4/19/2019 B.R

Socket Names Applications refer to sockets by name. But within the communication domain sockets are referred by addresses. Name to address translation is usually done outside the operating system. 4/19/2019 B.R

Socket types The format in which an address is specified is according to a domain: AF_UNIX (address format of UNIX) - a path name within the file system, AF_INET (internet format) : network address, port number etc. Communication style: stream , datagram, raw or sequenced packets Stream : reliable, error-free, connection-oriented comm. Datagram: Connectionless, unreliable, message boundaries preserved. Why use datagram? 4/19/2019 B.R

Socket API Creation: name, type, domain are specified Binding: bound to an address, port Close: release data structures and port Send and Receive: several versions Listen: Specify number of connections that can be accepted Accept and Connect: Wait for connection and connect to a socket respectively Other miscellaneous functions such as getsockname, gethostbyname etc. 4/19/2019 B.R

Functions : creation Socket creation : socket system call creates sockets on demand. sockid = socket (af, type, protocol); where sockid is an int, af - address family , AF_INET, AF_UNIX, AF_AAPLETALK etc. type - communication type: SOCK_STREAM, SOCK_DGRAM, SOCK_RAW etc. protocol - some domains have multiple protocol, use a 0 for your appl. Example: door1 = socket(AF_UNIX, SOCK_DGRAM,0); 4/19/2019 B.R

Functions - bind Socket binding: A socket is created without any association to local or destination address. It is possible to bind the socket to a specific host and in it a specific port number. socerr = bind (sockid, localaddr, addrlength) localaddr - a struct of a specific format for each address domain; addrlength - is the length of this struct; obtained usually by sizeof function. 4/19/2019 B.R

Functions -bind (contd.) Example: type sockaddr_un defines localaddr format for unix family. its definition, (you don’t have to define it... it is in un.h file - include this file) struct sockaddr_un { short sun_family; char sun_path[108]; }; in your program: #define SocName “testsock” sockaddr_un mysoc; mysoc.sun_family = AF_UNIX; strcpy(mysoc.sun_path, SocName); binderr = bind(sockid, &mysoc, sizeof(mysoc)); 4/19/2019 B.R

Functions (contd.) - close close (socid); closes the specified socket. This is done by a process or thread when it no longer needs the socket connection. Premature closing results in “broken pipe” error. When a socket is created it is represented by a special file (‘s’ in the place where d appears for directory files when you ls -l).The name of the file is the name assigned in the socket bind command. 4/19/2019 B.R

Functions (contd.) - connect A socket is created in an unconnected state, which means that the socket is not associated with any destination. An application program should call connect to establish a connection before it can transfer data thru’ reliable stream socket. For datagrams connect is not required but recommended. connect ( sockid, destaddr, addlength); Example: if (connect(sock, &server, sizeof(server)) < 0) ... (“sendto” commend does not need “connect” ) 4/19/2019 B.R

Functions (contd.) -sending Five different system calls : send, sendto, sendmsg, write, writev send, write and writev work only with connected sockets. No parameter for destination address. Prior connect should be present for communication. Example : write (sock, DATA, sizeof(DATA)); sendto (socket, message, length, flags, destaddr, addlen); flags allow for special processing of messages. sendmsg is same as sento except that it allows for different message structure. 4/19/2019 B.R

Functions(contd.) - receiving Five different calls are available: read, readv, recv, recvfrom, recvmsg read, readv, and recv are for connection-oriented comm. read(socdescriptor, buffer, length); Example: read(sock, buf, 1024); For your application (project) you may use read. For connectionless, datagram-kind : recvfrom(same set of params as sendto); except that message length and addr length return values. 4/19/2019 B.R

Functions (contd.) -listen accept and listen are connection-oriented communication. These are for AF_INET, SOCK_STREAM type of sockets. listen: To avoid having protocols reject incoming request, a server may have to specify how many messages need to be queued until it has time to process them. Example: listen(socket,length); accept: wait for the call. Example: accept(sockid, sockaddr, sizeof sockaddr); 4/19/2019 B.R

Functions (contd.) - accept accept : blocks until a connect calls the socket associated with this connection. socket -- bind --(listen) -- accept is the sequence. “connect” from calling process will complete the connection and unblock the process or thread that is blocked on “accept” Now read, write or writev can be executed to carry out the actual communication over the connection established. 4/19/2019 B.R

Functions (contd.) - getsockname getsockname (sockid, sockaddr, sizeof sockaddr); : given a sockid returns the address of the socket identified by sockid. This address may be needed, for instance, by an accept function call. There are other functions such as gethostbyname may be needed for internet domain sockets. See man pages for the details. 4/19/2019 B.R

Sockets used for datagrams ServerAddress and ClientAddress are socket addresses Sending a message Receiving a message bind(from, ClientAddress) sendto(from, "message", ServerAddress) bind(to, ServerAddress) amount = recvfrom(to, buffer, ClientAddress) to = socket(AF_INET, SOCK_DGRAM, 0) from = socket(AF_INET, SOCK_DGRAM, 0) 4/19/2019 B.R

Sockets used for streams Requesting a connection Listening and accepting a connection s = socket(AF_INET, SOCK_STREAM,0) s = socket(AF_INET, SOCK_STREAM,0) bind(s, ServerAddress); listen(s,5); connect(s, ServerAddress) sNew = accept(s, ClientAddress); write(s, "message", length) n = read(sNew, buffer, amount) ServerAddress and ClientAddress are socket addresses 4/19/2019 B.R

Sockets on Unix When a new process is created, the newly created process inherits access to all open sockets from its parent. For threads socket identifiers should be defined in the common address space or passed as parameters. include files : <socket.h>, <un.h> or <in.h>, and other related header files. When linking add a -lsocket –lnsl options besides. 4/19/2019 B.R