Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSCE 515: Computer Network Programming Chin-Tser Huang University of South Carolina.

Similar presentations


Presentation on theme: "CSCE 515: Computer Network Programming Chin-Tser Huang University of South Carolina."— Presentation transcript:

1 CSCE 515: Computer Network Programming Chin-Tser Huang huangct@cse.sc.edu University of South Carolina

2 2/22/20052 A Client/Server Multicast Chat System Each client unicasts its message to server Server then multicasts message to all clients Otherwise similar to MulticastChat discussed in last lecture: client opens a chat frame and starts a thread that listens for incoming packets

3 2/22/20053 MixedcastChat.java /* * Java Network Programming, Second Edition * Merlin Hughes, Michael Shoffner, Derek Hamner * Manning Publications Company; ISBN 188477749X * * http://nitric.com/jnp/ * * Copyright (c) 1997-1999 Merlin Hughes, Michael Shoffner, Derek Hamner; * all rights reserved; see license.txt for details. */ import java.io.*; import java.net.*; import java.awt.*; public class MixedcastChat extends MulticastChat { // public MixedcastChat (InetAddress group, int port, InetAddress server, int serverPort) … // protected void initNet () throws IOException… // public static void main (String[] args) throws IOException … }

4 2/22/20054 Constructor MixedcastChat protected InetAddress server; protected int serverport; public MixedcastChat (InetAddress group, int port, InetAddress server, int serverPort) { super (group, port); this.server = server; this.serverPort = serverPort; frame.setTitle ("MixedcastChat [" + group.getHostAddress () + ":" + port + "/" + server.getHostName () + ":" + serverPort + "]"); }

5 2/22/20055 Method initNet protected void initNet () throws IOException { super.initNet (); outgoing.setAddress (server); outgoing.setPort (serverPort); }

6 2/22/20056 Method main public static void main (String[] args) throws IOException { if ((args.length != 2) || (args[0].indexOf (":") < 0) || (args[1].indexOf (":") < 0)) throw new IllegalArgumentException ("Syntax: MixedcastChat : : "); int idx = args[0].indexOf (":"); InetAddress group = InetAddress.getByName (args[0].substring (0, idx)); int port = Integer.parseInt (args[0].substring (idx + 1)); idx = args[1].indexOf (":"); InetAddress server = InetAddress.getByName (args[1].substring (0, idx)); int serverPort = Integer.parseInt (args[1].substring (idx + 1)); MixedcastChat chat = new MixedcastChat (group, port, server, serverPort); chat.start (); }

7 2/22/20057 MixedcastServer.java /* * Java Network Programming, Second Edition * Merlin Hughes, Michael Shoffner, Derek Hamner * Manning Publications Company; ISBN 188477749X * * http://nitric.com/jnp/ * * Copyright (c) 1997-1999 Merlin Hughes, Michael Shoffner, Derek Hamner; * all rights reserved; see license.txt for details. */ import java.io.*; import java.net.*; public class MixedcastServer { // public static void main (String[] args) throws IOException… // protected static void init (int serverPort, InetAddress group, int port) throws IOException… // protected static void relay () throws IOException… }

8 2/22/20058 Method main public static void main (String[] args) throws IOException { if ((args.length != 2) || (args[1].indexOf (":") < 0)) throw new IllegalArgumentException ("Syntax: MixedcastServer : "); int serverPort = Integer.parseInt (args[0]); int idx = args[1].indexOf (":"); InetAddress group = InetAddress.getByName (args[1].substring (0, idx)); int port = Integer.parseInt (args[1].substring (idx + 1)); init (serverPort, group, port); while (true) { relay (); } // protected static void init (int serverPort, InetAddress group, int port) throws IOException… // protected static void relay () throws IOException…

9 2/22/20059 Method init protected static DatagramSocket inSocket; protected static MulticastSocket outSocket; protected static DatagramPacket incoming, outgoing; protected static void init (int serverPort, InetAddress group, int port) throws IOException { inSocket = new DatagramSocket (serverPort); outSocket = new MulticastSocket (); outSocket.setTimeToLive (1); byte[] buffer = new byte[65508]; incoming = new DatagramPacket (buffer, buffer.length); outgoing = new DatagramPacket (buffer, buffer.length, group, port); }

10 2/22/200510 Method relay protected static void relay () throws IOException { incoming.setLength (incoming.getData ().length); inSocket.receive (incoming); outgoing.setLength (incoming.getLength ()); outSocket.send (outgoing); }

11 2/22/200511 Internet Group Management Protocol (IGMP) Let all systems on a physical network know which hosts currently belong to which multicast groups IGMP messages are carried in IP datagrams Two types of messages: IGMP report and IGMP query Latest version is 3 (RFC 3376)

12 2/22/200512 IGMPv1 Message Format 0151631 8 bytes destination port number group address (class D IP address) unused IGMP type(1-2) IGMP version 3478

13 2/22/200513 Joining a Multicast Group A process joins a multicast group on a given interface on a host A process can join same group on multiple interfaces Membership in a multicast group on a given interface is dynamic: process can join and leave group at any time

14 2/22/200514 IGMP Operation A host sends an IGMP report when first process joins a group A multicast router sends an IGMP query with group address 0 at regular intervals on each interface A host responds to an IGMP query by sending one IGMP report for each group that still contains at least one process A host does not send a report when leaving a group; it just won’t report to next query

15 2/22/200515 IGMP Operation host multicast router IGMP report, TTL = 1, IGMP group addr = group address dest IP addr = group address src IP addr = host’s IP addr IGMP query, TTL = 1, IGMP group addr = 0 dest IP addr = 224.0.0.1 src IP addr = router’s IP addr

16 2/22/200516 Some Implementation Considerations A host sends out second copy of an initial IGMP report after a random delay To make sure the report is delivered A host does not respond to an IGMP query immediately; it schedules responses for later times If a host is scheduled to send a report but receives a copy of same report from other host, it can cancel the scheduled report

17 2/22/200517 Domain Name System (DNS) A distributed database used by TCP/IP applications to map between hostnames and IP addresses No single site on Internet knows all information; each site maintains its own database and let other sites query it DNS name space is hierarchical

18 2/22/200518 Hierarchical Organization of DNS arpacomedugovintmilnetorgaeuszw …… sc cse sc state wwwvega in-addr 118 130 252 129 United Arab Emirates Zimbabwe Unnamed root vega.cse.sc.eduwww.state.sc.us Generic domains Country domains

19 2/22/200519 DNS Tree Every node has a label of up to 63 characters Root of tree is a special node with null label Name of a leaf node stands for host name

20 2/22/200520 Domain Name Domain name of any node is the list of labels, starting at that node, working up to root, using a dot to separate labels Every node must have a unique domain name, but same label can be used at different nodes in the tree A domain name ending with a dot is called a fully qualified domain name (FQDN) Because it ends with root and root has null label

21 2/22/200521 Top-level Domains Three areas of top-level domains arpa, a special domain used for address- to-name mappings Seven 3-character generic domains com, edu, gov, int, mil, net, org 2-character country domains

22 2/22/200522 DNS Zone A subtree of DNS tree that is administered separately A second-level domain is a common zone, and is divided into smaller zones Each zone has a primary name server and one or more secondary name server To avoid single point of failure

23 2/22/200523 DNS Operation When a new system is added to a zone, DNS administrator for the zone assigns a name and an IP address and stores information in name server To resolve a name or address, client can send DNS query message to a name server of its zone

24 2/22/200524 DNS Operation (cont’d) When a name server is queried, it first searches its database If found, reply with a DNS response message If not found, contact a root name server, and root name server contacts a second-level name server, continues iteratively until an answer of yes or no A name server caches received information about a mapping to reduce DNS traffic

25 2/22/200525 DNS Message Format number of additional RRs answers (variable number of resource records) 0151631 questions number of authority RRs number of answer RRsnumber of questions flagsidentification authority (variable number of resource records) additional information (variable number of resource records) 12 bytes

26 2/22/200526 Format of question Portion of DNS Query query class 0151631 query name query type

27 2/22/200527 Format of DNS Resource Record class resource data 0151631 time-to-live domain name type resource data length

28 2/22/200528 Next Class TCP Read TI Ch. 17, 18 Homework 2 will be passed out


Download ppt "CSCE 515: Computer Network Programming Chin-Tser Huang University of South Carolina."

Similar presentations


Ads by Google