Department of Computer Science Southern Illinois University Edwardsville Spring, 2010 Dr. Hiroshi Fujinoki CS 547/490 Network.

Slides:



Advertisements
Similar presentations
Florida State UniversityCOP Advanced Unix Programming Raw Sockets Datalink Access Chapters 25, 26.
Advertisements

Programming with UDP – I Covered Subjects: IPv4 Socket Address Structure Byte Ordering Functions Address Access/Conversion Functions Functions: 1.socket()
Multicasting - Part II© Dr. Ayman Abdel-Hamid, CS4254 Spring CS4254 Computer Network Architecture and Programming Dr. Ayman A. Abdel-Hamid Computer.
MULTICAST USING UDP SOCKETS. PRELIMINARIES *CAST Unicast Communication is strictly from one sender to another specified receiver eg: TCP on LAN Broadcast.
Sockets Basics Conectionless Protocol. Today IPC Sockets Basic functions Handed code Q & A.
1 Socket Interfaces Professor Jinhua Guo CIS527 Fall 2003.
Multicasting Jari Kellokoski Introduction When a unicast address identifies a sigle IP interface Then a broadcast address identifies all IP.
Tutorial 8 Socket Programming
CS 311 – Lecture 18 Outline IPC via Sockets – Server side socket() bind() accept() listen() – Client side connect() Lecture 181CS Operating Systems.
The Basics of communication LectureII. Processing Techniques.
2: Application Layer 1 Chapter 2 Application Layer Computer Networking: A Top Down Approach, 5th edition. Jim Kurose, Keith Ross Addison-Wesley, April.
User Datagram Protocol An initial look at using the UDP transport protocol for sending and receiving network packets.
Client Software Design Objectives: Understand principles of C/S design, with focus on clients Review Windows implementations of Socket functions.
Broadcast and Multicast. Unicast Host 2Host 1 Broadcast Packet received by every host on network (including the sender!)
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.
Socket programming in C. Socket programming Socket API introduced in BSD4.1 UNIX, 1981 explicitly created, used, released by apps client/server paradigm.
Socket Programming References: redKlyde ’ s tutorial set Winsock2 for games (gamedev.net)
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.
Fall 2000Datacom 11 Socket Programming Review Examples: Client and Server-Diagnostics UDP versus TCP Echo.
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.
Class A Addresses The 1 st bit of a class A address is 0 The 1 st byte has a value from (128.x.x.x would not be a class A) 127.x.x.x is reserved.
Sirak Kaewjamnong Computer Network Systems
Department of Computer Science Southern Illinois University Edwardsville Spring, 2010 Dr. Hiroshi Fujinoki CS 547/490 Network.
Multicasting. References r Note: Some slides come from the slides associated with this book: “Mastering Computer Networks: An Internet Lab Manual”, J.
Department of Computer Science Southern Illinois University Edwardsville Spring, 2008 Dr. Hiroshi Fujinoki FTP Protocol Programming.
Sockets API Overview Sockets with UDP Sockets with TCP Fast Sockets (Fast UDP) IP Multicasting.
 Wind River Systems, Inc Chapter - 13 Network Programming.
CS 447 Networks and Data Communication ARP (Address Resolution Protocol) for the Internet Department of Computer Science Southern Illinois University Edwardsville.
Chapter 2 Applications and Layered Architectures Sockets.
Technical Details for sockaddr_in Structure Department of Computer Science Southern Illinois University Edwardsville Fall, 2015 Dr. Hiroshi Fujinoki
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.
TELE202 Lecture 15 Socket programming 1 Lecturer Dr Z. Huang Overview ¥Last Lecture »TCP/UDP (2) »Source: chapter 17 ¥This Lecture »Socket programming.
CSCE 515: Computer Network Programming UDP Socket Wenyuan Xu Department of Computer Science and Engineering.
Introduction to Socket
Socket Programming Tutorial Department of Computer Science Southern Illinois University Edwardsville Fall, 2015 Dr. Hiroshi Fujinoki
Sockets Socket = abstraction of the port concept: –Application programs request that the operating system create a socket when one is needed –O.S. returns.
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.
TELE 402 Lecture 8: Broadcast and Multicast 1 Overview Last Lecture –IPv6 This Lecture –Broadcast and multicast sockets –Source: Chapters 20&21 of Stevens’
Read() recv() connection establishment Server (connection-oriented protocol) blocks until connection from client Client socket() bind() listen() accept()
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.
CS 447 Networks and Data Communication Server-Process Organization IP address and SockAddr_In Data Structure Department of Computer Science Southern Illinois.
Socket programming in C. Socket programming with TCP Client must contact server server process must first be running server must have created socket (door)
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.
SOCKET PROGRAMMING Presented By : Divya Sharma.
Jim Fawcett CSE 681 – Software Modeling & Analysis Fall 2002
CS 1652 Jack Lange University of Pittsburgh
Jim Fawcett CSE 687-OnLine – Object Oriented Design Summer 2017
Jim Fawcett CSE 775 – Distributed Objects Spring 2007
Socket Programming in C
Network Programming with Sockets
Review: TCP Client-Server Interaction
Transport layer API: Socket Programming
UDP Sockets Programming
Chapter 07. Socket Options.
Socket Programming.
Chapter 06. UDP Server/Client.
Chapter 3 Socket API © Bobby Hoggard, Department of Computer Science, East Carolina University These slides may not be used or duplicated without permission.
Jim Fawcett CSE 681 – Software Modeling & Analysis Summer 2003
Presentation transcript:

Department of Computer Science Southern Illinois University Edwardsville Spring, 2010 Dr. Hiroshi Fujinoki CS 547/490 Network Programming IP Multicast/000 IP Multicast - Program Implementation

CS 547 Advanced Network Programming Unicast Server and Clients IP Multicast 2/002 Client Time Server A client initiates a session to get a reply from a server “Pull” Model Message Request

CS 547 Advanced Network Programming Multicast Server and Clients IP Multicast 2/003 Client 1 Client 2 Client 3 Time Server Multicast sender “sends” message to clients “Push” Model Message

CS 547 Advanced Network Programming Procedures in Client and Server Process IP Multicast/004 Initialize socket Socket() Set Local Address/Port Bind() Join a multicast group Set TTL value Disable Loop-back Set Multicast Address sendto() closesocket() SERVER CLIENT Initialize socket Socket() Reuse Socket Bind() Join a multicast group recvfrom() closesocket() UDP Connection-less transmission

IP Multicast 2/004 CS 547 Advanced Network Programming Initialize socket WSADATA stWSAData; // status = WSAStartup(0X0202, &stWSAData); WinSock Version Number (Ver. 2.2) WinSock data strcuture Execution status Make sure Winsock 2.X

Socket_ID = socket(AF_INET, SOCK_DGRAM, 0); AF_INET for IP SOCK_DGRAAM for UDP session Socket ID to identify this socket session IP Multicast 2/005 CS 547 Advanced Network Programming Get a datagram socket AF_INET = IP GRAM = UDP

IP Multicast 2/006 CS 547 Advanced Network Programming Set the local IP address and port number stLclAddr.sin_family= AF_INET; stLclAddr.sin_addr.s_addr= htonl (INADDR_ANY); stLclAddr.sin_port= 0; SOCKADDR_IN stLclAddr;

IP Multicast 2/007 CS 547 Advanced Network Programming Bind the socket status = bind (Socket_ID, (struct sockaddr *) &stLclAddr, sizeof (stLclAddr); Pointer to stLclAddr structure Byte size of the stLclAddr structure Socket ID to identify this socket session

IP Multicast 2/008 CS 547 Advanced Network Programming Join the multicast group stMreq.imr_multiaddr.s_addr = inet_addr (archMCAddr) stMreq.imr_interface.s_addr = INADDR_ANY; status = setsockopt (Socket_ID, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *) &stMreq, sizeof (stMreq)); Multicast Address (Class-D IP Address) Any NIC if multiple NICs exist Join a multicast group Multicast IP address (Class-D) is a multicast group ID

IP Multicast 2/009 CS 547 Advanced Network Programming Set TTL status = setsockopt (Socket_ID, IPPROTO_IP, IP_MULTICAST_TTL, (char *) &lTTL, sizeof (lTTL)); strcpy (lTTL, “2”); u_long lTTL; // Declare variable TTL lTTL = (u_long)3; // Assign TTL value Specify the reach of the multicast messages

IP Multicast 2/010 CS 547 Advanced Network Programming Disable Loop-back status = setsockopt (Socket_ID, IPPROTO_IP, IP_MULTICAST_LOOP, (char *) &fFlag, sizeof (fFlag)); BOOL fFlag; // Declare variable loop-back Flag fFlag = FALSE; // Reset the loop-back flag Loop-back = FALSE -> The Multicast sender will not receiver its message

IP Multicast 2/011 CS 547 Advanced Network Programming Specify Multicast Address stDstAddr.sin_family = AF_INET; stDstAddr.sin_addr.s_addr = inet_addr (achMCAddr); stDstAddr.sin_port = htons (nPort); stDstAddr

IP Multicast 2/012 CS 547 Advanced Network Programming Transmit a multicast message status = sendto (Socket_ID, (char *) &stSysTime, sizeof (stSysTime), 0, (struct sockaddr *)&sdDstAddr, sizeof (stDstAddr)); Close socket connection status = closesocket (Socket_ID);

IP Multicast 2/013 CS 547 Advanced Network Programming Procedures in the client side

Initialize socket IP Multicast 2/014 Same as the server process Get a datagram socket Same as the server process CS 547 Advanced Network Programming

IP Multicast/015 Initialize socket Socket() Set Local Address/Port Bind() Join a multicast group Set TTL value Disable Loop-back Set Multicast Address sendto() closesocket() SERVER CLIENT Initialize socket Socket() Reuse Socket Bind() Join a multicast group recvfrom() closesocket() Leave a group Problem (Bind Problem) Possible Bind problem

Step 3: Reuse Socket IP Multicast 2/016 CS 547 Advanced Network Programming Network Application Transport Protocol (TCP/UDP) Network Protocol (IP)LLC/MAC Protocol Network NW Interface Operating System Device Driver closesocket () only delete this

IP Multicast 2/017 CS 547 Advanced Network Programming Three techniques to solve this problem (1) Hard disconnection – zero lingering (2) Use different port # for each bind (3) Socket reuse

IP Multicast 2/018 CS 547 Advanced Network Programming Hard Disconnection Network Application Transport Protocol (TCP/UDP) Network Protocol (IP)LLC/MAC Protocol Network closesocket () only delete this Always destroy the connection

IP Multicast 2/019 CS 547 Advanced Network Programming Hard Disconnection Disadvantage: Part of the last message could be lost

CS 547 Advanced Network Programming IP Multicast/020 Initialize socket Socket() Set Local Address/Port Bind() Join a multicast group Set TTL value Disable Loop-back Set Multicast Address sendto() closesocket() SERVER CLIENT Initialize socket Socket() Bind() Join a multicast group recvfrom() closesocket() Leave a group Use different # for each iteration Use different Port number

IP Multicast 2/021 CS 547 Advanced Network Programming Disadvantage: Use different # for each iteration One process (program) might consumes many port numbers

CS 547 Advanced Network Programming IP Multicast/022 Initialize socket Socket() Set Local Address/Port Bind() Join a multicast group Set TTL value Disable Loop-back Set Multicast Address sendto() closesocket() SERVER CLIENT Initialize socket Socket() Reuse Socket Bind() Join a multicast group recvfrom() closesocket() Leave a group Possible Bind problem Socket Reuse

Step 3: Socket Reuse IP Multicast 2/023 CS 547 Advanced Network Programming int status = setsockopt (socket_id, SOL_SOCKET, SO_REUSEADDR, (char *)&fFlag, sizeof (fFlag)); BOOL fFlag; fFlag =FALSE; Socket ID SOL_SOCKET constant To reuse a socket Pointer to the Boolean variable

IP Multicast 2/024 CS 547 Advanced Network Programming Set the local IP address and port number stLclAddr.sin_family= AF_INET; stLclAddr.sin_addr.s_addr= htonl (INADDR_ANY); stLclAddr.sin_port= 0; SOCKADDR_IN stLclAddr;

IP Multicast 2/025 CS 547 Advanced Network Programming Bind the socket status = bind (socket_ID, (struct sockaddr *) &stLclAddr, sizeof (stLclAddr); Pointer to stLclAddr structure Byte size of the stLclAddr structure Socket ID to identify this socket session

IP Multicast 2/026 CS 547 Advanced Network Programming Join the multicast group stMreq.imr_multiaddr.s_addr = (achMCAddr); stMreq.imr_interface.s_addr = INADDR_ANY; status = setsockopt (socket_id, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *) &stMreq, sizeof (stMreq));

IP Multicast 2/027 CS 547 Advanced Network Programming Join the multicast group struct ip_mreq stMreq; // Create Multicast interface Structure char achMCAddress[20]; // IP Multicast Address Holder strcpy (achMCAddress, “ ”); Assign multicast address

IP Multicast 2/028 CS 547 Advanced Network Programming Receive a multicast message status = recvfrom (socket_ID, (char *) achInBuf, BUFF_SIZE, 0, (struct sockaddr *)&stSrcAddr, &addr_size); Close socket connection status = closesocket (socket_ID); int addr_size = sizeof (stSrcAddr);

IP Multicast 2/029 CS 547 Advanced Network Programming Leaving the multicast group int status = setsockopt (socket_id, IPPPROTO_IP, IP_DROP_MEMBERSHIP, (char *)stMreq, sizeof (stMreq)); Socket ID IPPROTO_IP constant To drop a multicast group Multicast Interface Structure Size of the structure

IP Multicast 2/030 CS 547 Advanced Network Programming stMreq.imr_multiaddr.s_addr = (achMCAddr); stMreq.imr_interface.s_addr = INADDR_ANY; Leaving the multicast group Specify from which multicast group you are leaving Specify which interface should be removed from the group setsockopt(my_socket, IPPROTO, IP_DROP_MEMBERSHIP, (char *)stMreq, sizeof(stMreq));

IP Multicast 2/031 CS 547 Advanced Network Programming Clean up winsock object Close socket connection status = closesocket (socket_ID);WASCleanup();

IP Multicast 2/020 CS 547 Advanced Network Programming How to get the current system time (1) ? Server Side Declaration SYSTEMTIME stSystemTime; // Hold the current time System Call GetSystemTime (&stSystemTime); // Get the current system time On transmission, you should typecast it to char pointer: (char *) &stSystemTime

IP Multicast 2/021 CS 547 Advanced Network Programming How to get the current system time (2) ? Client Side (1) Declaration SYSTEMTIME stSystemTime; // Hold the current time SYSTEMTIME * lpstSysTime; // Pointer of type SYSTIME

IP Multicast 2/022 CS 547 Advanced Network Programming How to get the current system time (3) ? SYSTEMTIME stSystemTime; // Hold the current time SYSTEMTIME * lpstSysTime; // Pointer of type SYSTIME char achInBuff [BUF_SIZE] // Char string for receiving a message lpstSysTime = (SYSTEMTIME *)achInBuf; recvfrom (Socket_ID, achInBuf, BUF_SIZE, 0, (struct sockaddr *)&stSrcAddr, &addr_size); SetSystemTime (lpstSysTime); GetSystemTime (stSystemTime); [Display the updated current system time]

IP Multicast 2/023 CS 547 Advanced Network Programming How to get the current system time (4) ? printf (“The local time update to %02d-%02d-%02d at %02d-%02d-%02d\n”, stSysTime.wMonth, stSysTime.wDay, stSysTime.wYear, stsSyTime.wHour, stSysTime.wMinute, stSysTime.wSecond, stSysTime.wMillisecond); ! Blue Bold - Member variables in stSysTime structure.

CS 547 Advanced Network Programming Client and Server Program Structure IP Multicast/024 Initialize socket Socket() Set Local Address/Port Bind() Join a multicast group Set TTL value Disable Loop-back Set Multicast Address sendto() closesocket() SERVER CLIENT Initialize socket Socket() ??? Bind() Join a multicast group recvfrom() closesocket()