Advanced Sockets API-II Vinayak Jagtap

Slides:



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

Sockets: Network IPC Internet Socket UNIX Domain Socket.
Programming with UDP – I Covered Subjects: IPv4 Socket Address Structure Byte Ordering Functions Address Access/Conversion Functions Functions: 1.socket()
TELE 402 Lecture 11: Advanced UDP… 1 by Dr Z. Huang Overview Last Lecture –Nonblocking I/O and ioctl operations –Source: Chapter 16 & 17 of Stevens’ book.
Sockets CS 3516 – Computer Networks. Outline Socket basics Socket details (TCP and UDP) Socket options Final notes.
Distributed Computing Systems Sockets. Outline Socket basics Socket details (TCP and UDP) Socket options Final notes.
Networks: TCP/IP Socket Calls1 Elementary TCP Sockets Chapter 4 UNIX Network Programming Vol. 1, Second Ed. Stevens.
Computer Networks Sockets.
Elementary TCP Sockets Chapter 4 UNIX Network Programming Vol. 1, Second Ed. Stevens.
Socket Programming.
Multimedia Networking Sockets. Outline Socket basics Socket details (TCP and UDP) Socket options Final notes.
Sockets Basics Conectionless Protocol. Today IPC Sockets Basic functions Handed code Q & A.
Sockets IMGD Outline Socket basics Socket details (TCP and UDP) Socket options Final notes.
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.
Computer Networks Sockets. Outline F Socket basics F Socket details.
Operating Systems Sockets. Outline F Socket basics F TCP sockets F Socket details F Socket options F Final notes F Project 3.
Lecture 8 UDP Sockets & I/O Multiplexing
UNIX Sockets COS 461 Precept 1.
Sockets CIS 370 Fall 2009, UMassD. Introduction  Sockets provide a simple programming interface which is consistent for processes on the same machine.
Elementary UDP Sockets© Dr. Ayman Abdel-Hamid, CS4254 Spring CS4254 Computer Network Architecture and Programming Dr. Ayman A. Abdel-Hamid Computer.
1 Introduction to Raw Sockets 2 IP address Port address MAC address TCP/IP Stack 67 Bootp DHCP OSPF protocol frame type UDP Port # TCP Port.
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.
Socket Programming. Introduction Sockets are a protocol independent method of creating a connection between processes. Sockets can be either – Connection.
University of Calgary – CPSC 441.  UDP stands for User Datagram Protocol.  A protocol for the Transport Layer in the protocol Stack.  Alternative to.
CS345 Operating Systems Φροντιστήριο Άσκησης 2. Inter-process communication Exchange data among processes Methods –Signal –Pipe –Sockets.
9/12/2015B.R1 Socket Abstraction and Interprocess Communication B.Ramamurthy CSE421.
Sockets CIS 370 Lab 10 UMass Dartmouth. Introduction 4 Sockets provide a simple programming interface which is consistent for processes on the same machine.
 Wind River Systems, Inc Chapter - 13 Network Programming.
Review: How to create a TCP end point? What is the right format for sin_port and sin_addr in the sockaddr_in data structure? How many different ways we.
Chapter 2 Applications and Layered Architectures Sockets.
Remote Shell CS230 Project #4 Assigned : Due date :
TELE 402 Lecture 10: Unix domain … 1 Overview Last Lecture –Daemon processes and advanced I/O functions This Lecture –Unix domain protocols and non-blocking.
1 Unix Domain Protocols when client and server are on the same host Unix domain socket address structure Socket functions Stream client-server Datagram.
Networking Tutorial Special Interest Group for Software Engineering Luke Rajlich.
CPSC 441 TUTORIAL – FEB 13, 2012 TA: RUITNG ZHOU UDP REVIEW.
Distributed Computing A Programmer’s Perspective.
Cli/Serv.: sockets 3/91 Client/Server Distributed Systems v Objectives –describe iterative clients and servers using the UDP protocol ,
CSCE 515: Computer Network Programming UDP Socket Wenyuan Xu Department of Computer Science and Engineering.
TELE 402 Lecture 9: Daemon … 1 by Dr Z. Huang Overview Last Lecture –Broadcast and multicast This Lecture –Daemon processes and advanced I/O functions.
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
Programming with UDP – II Covered Subjects: Creating UDP sockets Client Server Sending data Receiving data Connected mode.
Today’s topic: UDP Reliable communication over UDP.
S OCKET P ROGRAMMING IN C Professor: Dr. Shu-Ching Chen TA: HsinYu Ha.
Review: –Concurrent server and multiplexed server How they work? Which one is better?
Introduction to Sockets
S OCKET P ROGRAMMING IN C Professor: Dr. Shu-Ching Chen TA: Hsin-Yu Ha.
CMPT 471 Networking II Network Programming © Janice Regan,
UNIX Network Programming1 Chapter 13. Advanced I / O Functions.
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 3 TCP and UDP Sockets CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger.
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.
1 UDP Sockets Programming Creating UDP sockets.Creating UDP sockets. –Client –Server Sending data.Sending data. Receiving data.Receiving data. Connected.
UNIX Sockets COS 461 Precept 1.
Elementary UDP Sockets
Socket Programming in C
CHAPTER 8 ELEMENTARY UDP SOCKETS
UDP Sockets Programming
Socket Programming in C
Advanced Network Programming spring 2007
Advanced I/O Functions
Internet Networking recitation #8
Sockets.
Socket Programming with UDP
Presentation transcript:

Advanced Sockets API-II Vinayak Jagtap

UDP Sockets

Socket Functions for UDP client/server socket() bind() socket() sendto() recvfrom() close() recvfrom() sendto() Data (request) Data (reply) Client Server Process request

Application details Applications will have to do for themselves Acknowledgement of packets Flow control Sequencing

Function for sending data #include int sendto(int sockfd, char* buf, int nbytes, int flags, struct sockaddr* to, int addrlen); Return value: No. of bytes sent if OK, -1 on error Flags argument is either 0 or is formed by OR’ing some constants like: MSG_DONTROUTE Bypass routing MSG_DONTWAIT Enable non-blocking operation

Function for receiving data #include int recvfrom(int sockfd, char* buf, int nbytes, int flags, struct sockaddr* from, int* addrlen); Return value: No. of bytes read if OK, -1 on error Flags argument is either 0 or is formed by OR’ing some constants like: MSG_PEEK Peek at data present on socket MSG_DONTWAIT Enable non-blocking operation

Simple Echo client/server using UDP UDP ClientUDP Server sendto recvfrom sendto recvfrom fgets fputs

Features of the UDP server Echo function never terminates. Iterative Server

connect() for UDP! Connect can be done on a udp socket to specify destination address and port Does not do any TCP like connection send can be used instead of sendto as destination address is known. Receive operations will accept data only from the specified source, and Send operations can send only to the specified destination. Disconnection can be done by calling connect() with family member (eg sin_family) set to AF_UNSPEC

connect() Advantages: Is more efficient (due to avoidance of multiple internal connects) Asynchronous errors (e.g., ICMP errors) can be detected.

Connected UDP Socket Application UDP connected peer UDP Datagram from other IP read write

Getsockbyname() #include int getsockname(int s, struct sockaddr *name, socklen_t *namelen); Getsockname returns the current name for the specified socket. On success, zero is returned. On error, -1 is returned, and errno is set appropriately. ERRORS EBADF The argument s is not a valid descriptor. ENOTSOCK The argument s is a file, not a socket. ENOBUFS Insufficient resources available in the system to perform the operation. EFAULT The name parameter points to memory not in a valid part of the process address space.

UDP When to use? Applications use broadcasting or multicasting Cost of connection establishment is high compared to data transferred When not to use? Flow control is very important Packet sequence has to be maintained E.g. DNS name query, SNMP

Timeouts SIGALARM

Extended I/O Functions int send(int sockfd, const void *msg, size_t len, int flags) int recv(int sockfd, const void *buff, size_t len, int flags) MSG_OOB 0x1 process out-of-band data MSG_DONTROUTE 0x4 bypass routing, use direct interface MSG_DONTWAIT 0x40 don't block MSG_NOSIGNAL 0x2000 don't raise SIGPIPE

Extended I/O functions #include int readv(int fd, const struct iovec * vector, int count); int writev(int fd, const struct iovec * vector, int count); They return number of bytes read/written on success, -1 on failure struct iovec { void* iov_base; /* Starting address. */ size_t iov_len; /* Length in bytes. */ }

Extended I/O functions #include int recvmsg(int sockfd, struct msghdr *msg, int flags); int sendmsg(int sockfd, const struct msghdr *msg, int flags); They return number of bytes read/written on success, -1 on failure struct msghdr { void * msg_name; /* protocol address */ socklen_t msg_namelen; /* size of address */ struct iovec * msg_iov; /* scatter/gather array */ size_t msg_iovlen; /* # elements in msg_iov */ void * msg_control; /* ancillary data */ /*aligned for struct cmsghdr*/ socklen_t msg_controllen; /* ancillary data buffer len */ int msg_flags; /* flags on received message */ };

UNIX Domain Protocols A way of performing client-server communication on a single host using the sockets (or XTI) API They are an alternative to IPC

UNIX Domain Protocols Reasons to use: It is better to use them for networked applications residing on the same host because they increase the efficiency of I/O. They are light weight in comparison with the TCP/IP stack. E.g.: X-Windows applications Newer implementations provide the client’s credentials (user ID and group ID) to server

UNIX Domain Socket Address Structure In struct sockaddr_un { sa_family_t sun_family; /* AF_LOCAL */ char sun_path[104]; /* null terminated path name*/ };

UNIX Domain Protocols Family is AF_LOCAL/AF_UNIX A pathname is chosen in the address information

UNIX Domain Protocols Types of sockets provided: Stream sockets Datagram sockets Raw sockets (poorly documented)

References Unix Network Programming, Volume I W. Richard Stevens