Chapter 06. UDP Server/Client.

Slides:



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

Programming with UDP – I Covered Subjects: IPv4 Socket Address Structure Byte Ordering Functions Address Access/Conversion Functions Functions: 1.socket()
UDP and Multi-thread Socket Programming
Sockets Basics Conectionless Protocol. Today IPC Sockets Basic functions Handed code Q & A.
Socket Programming: a Primer Socket to me!. Feb. 23, 2001EE122, UCB2 Why does one need sockets? application network protocol sockets network.
Windows Sockets Purpose Windows Sockets 2 (Winsock) enables programmers to create advanced internet, intranet, and other network-capable applications to.
תקשורת באינטרנט Tutorial 8. 2 n Socket programming u What is socket ? u Sockets architecture u Types of Sockets u The Socket system calls u Data Transfer.
1 Pertemuan 10 Non Blocking Matakuliah: H0483 / Network Programming Tahun: 2005 Versi: 1.0.
Tutorial 8 Socket Programming
TDC561 Network Programming Camelia Zlatea, PhD Week 2 – part II: Socket Application Programming Interface.
Programming with Berkeley Sockets Presented by Chris GauthierDickey Written by Daniel Stutzbach (I think!) for CIS 432/532 Useful References: ● man pages.
Winsock programming.  TCP/IP UDP TCP  Winsock #include wsock32.lib.
Client Software Design Objectives: Understand principles of C/S design, with focus on clients Review Windows implementations of Socket functions.
Reliable Data Transfer Protocol IMPLEMENTATION TIPS.
Ashutosh Shukla Lecture 3 Network Programming CS 640: Computer Networking.
TCP Socket Programming. r An abstract interface provided to the application programmer  File descriptor, allows apps to read/write to the network r Allows.
CS1652 September 13th, 2012 The slides are adapted from the publisher’s material All material copyright J.F Kurose and K.W. Ross, All Rights.
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.
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.
University of Calgary – CPSC 441.  UDP stands for User Datagram Protocol.  A protocol for the Transport Layer in the protocol Stack.  Alternative to.
Chapter 17 Networking Dave Bremer Otago Polytechnic, N.Z. ©2008, Prentice Hall Operating Systems: Internals and Design Principles, 6/E William Stallings.
IT COOKBOOK Windows Network Programming. Chapter 01. Intro. to Network and Socket Programming.
Sockets API Overview Sockets with UDP Sockets with TCP Fast Sockets (Fast UDP) IP Multicasting.
Lab #1: Network Programming using Sockets By J. H. Wang Nov. 28, 2011.
Chapter 2 Applications and Layered Architectures Sockets.
Network Programming Eddie Aronovich mail:
Remote Shell CS230 Project #4 Assigned : Due date :
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.
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.
CSCE 515: Computer Network Programming UDP Socket Wenyuan Xu Department of Computer Science and Engineering.
Introduction to Socket
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,
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?
S OCKET P ROGRAMMING IN C Professor: Dr. Shu-Ching Chen TA: Hsin-Yu Ha.
Review: – Why layer architecture? – peer entities – Protocol and service interface – Connection-oriented/connectionless service – Reliable/unreliable service.
Read() recv() connection establishment Server (connection-oriented protocol) blocks until connection from client Client socket() bind() listen() accept()
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.
UNIX Sockets Outline UNIX sockets CS 640.
1 Spring Semester 2008, Dept. of Computer Science, Technion Internet Networking recitation #7 Socket Programming.
Department of Computer Science Southern Illinois University Edwardsville Spring, 2010 Dr. Hiroshi Fujinoki CS 547/490 Network.
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.
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.
UDP Socket Programming
Part 2 Socket Programming UDP.
CS 1652 Jack Lange University of Pittsburgh
Socket Programming in C
CHAPTER 8 ELEMENTARY UDP SOCKETS
Transport layer API: Socket Programming
UNIX Sockets Outline Homework #1 posted by end of day
UDP Sockets Programming
Chapter 07. Socket Options.
Socket Programming in C
Chapter 16 Socket Interface.
CSC Advanced Unix Programming, Fall 2015
Socket Programming(1/2)
Chapter 04. TCP Server/Client.
Internet Networking recitation #8
Presentation transcript:

Chapter 06. UDP Server/Client

Understanding the basic structure and principle of UDP server/client Goal Understanding the basic structure and principle of UDP server/client Learning socket system calls for UDP application Understanding broadcasting concept and UDP based implementation

Similarity of TCP and UDP Addressing based on port number Checking data error

Differences between TCP and UDP item TCP UDP ① connection-oriented protocol - Data comm. after connection setup Connectionless protocol - Data comm. without connection ② - byte-stream service - Datagram service ③ Reliable data transfer - By data retransmission Unreliable data transfer - No data retransmission ④ unicast Unicast, Broadcast, Multicast

UDP server/client operation (1/2)

UDP server/client operation (2/2) UDP server/client operation (cont’d) UDP server UDP server . . . Comm. Comm. UDP client #1 UDP client #2 UDP client #1 . . . UDP client #n

UDP server/client example Code example UDP client UDP server fgets() sendto() printf() recvfrom()

UDP server/client analysis (1/4) UDP/IP Socket requires three components ① protocol Defined by Socket() system call ② local IP address and port number Server or client side ③ remote IP address and port number

UDP server/client analysis (2/4) Socket data structure server Local IP addr Local port num Remote IP addr Remote port num client application OS network • • • Recvfrom buffer Sendto buffer

UDP server/client analysis (3/4) UDP server/client structure ① socket() bind() recvfrom() sendto() closesocket() UDP server UDP client network

UDP server/client analysis (4/4) UDP server/client structure ② (Ignore!!) socket() bind() recvfrom() sendto() closesocket() send() recv() UDP server UDP client network connect()

data transfer system call (1/4) sendto() send application data to peer side int sendto ( SOCKET s, const char* buf, int len, int flags, const struct sockaddr* to, int tolen ) ; success: num. of bytes sent, fail: SOCKET_ERROR

data transfer system call (2/4) sendto() example // initialize socket address structure to receiver address SOCKADDR_IN serveraddr; ... // declare buffer for sending data char buf[BUFSIZE]; // store sending data to buffer // data sending. retval = sendto(sock, buf, strlen(buf), 0, (SOCKADDR *)&serveraddr, sizeof(serveraddr)); if(retval == SOCKET_ERROR) error handling; printf("%d bytes sent...\n", retval);

data transfer system call (3/4) recvfrom() Data receving from peer side int recvfrom ( SOCKET s, char* buf, int len, int flags, struct sockaddr* from, int* fromlen ) ; success: num. of bytes sent, fail: SOCKET_ERROR

data transfer system call (4/4) recvfrom() example // initialize socket address structure to sender address SOCKADDR_IN peeraddr; int addrlen; // declare buffer for received data char buf[BUFSIZE]; // data receiving addrlen = sizeof(peeraddr); retval = recvfrom(sock, buf, BUFSIZE, 0, (SOCKADDR *)&peeraddr, &addrlen); if(retval == SOCKET_ERROR) error handling; printf("%d bytes received...\n", retval);

Communication types broadcasting (1/6) unicasting broadcasting multicasting

Broadcasting principle sender

Procedure to send broadcast data broadcasting (3/6) Procedure to send broadcast data ① Enable broadcast option for a socket BOOL bEnable = TRUE; retval = setsockopt(sock, SOL_SOCKET, SO_BROADCAST, (char *)&bEnable, sizeof(bEnable)); if(retval == SOCKET_ERROR) err_quit("setsockopt()");

Procedure to send broadcast data (cont’d) broadcasting (4/6) Procedure to send broadcast data (cont’d) ② Sending data to broadcast address // initialize socket address structure SOCKADDR_IN remoteaddr; ZeroMemory(&remoteaddr, sizeof(remoteaddr)); remoteaddr.sin_family = AF_INET; remoteaddr.sin_port = htons(9000); remoteaddr.sin_addr.s_addr = htonl(INADDR_BROADCAST); // store data to buffer char buf[BUFSIZE]; ... // sending data. retval = sendto(sock, buf, strlen(buf), 0, (SOCKADDR *)&remoteaddr, sizeof(remoteaddr)); if(retval == SOCKET_ERROR) error handling; printf("%d bytes sent….\n", retval);

Broadcast address broadcasting (5/6) host ID 11 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 network ID 11 . . . . . . . . . . . . 1 Network-directed broadcast local broadcast 11 . . . 1 subnet-directed broadcast subnet ID

Network-directed broadcast broadcasting (6/6) Broadcast address (cont’d) BroadcastSender.cpp, BroadcastReceiver.cpp router Network-directed broadcast router Local broadcast