Multicast Sockets What is a multicast socket? –unicast sockets provide a point to point...

30
Multicast Sockets • What is a multicast socket? – unicast sockets provide a point to point connection. There is one sender and one receiver. – Multicast sockets have one sender and many receivers

Transcript of Multicast Sockets What is a multicast socket? –unicast sockets provide a point to point...

Page 1: Multicast Sockets What is a multicast socket? –unicast sockets provide a point to point connection. There is one sender and one receiver. –Multicast sockets.

Multicast Sockets

• What is a multicast socket?– unicast sockets provide a point to point

connection. There is one sender and one receiver.

– Multicast sockets have one sender and many receivers

Page 2: Multicast Sockets What is a multicast socket? –unicast sockets provide a point to point connection. There is one sender and one receiver. –Multicast sockets.

Unicast vs. Multicast

s e n de r re ce iv e r

O n e - to -o n e co m m u n ica t io n o r u n ica s t G ro u p co m m u n ica t io n o r m u lt ica s t

Page 3: Multicast Sockets What is a multicast socket? –unicast sockets provide a point to point connection. There is one sender and one receiver. –Multicast sockets.

Why doesn’t everyone use Mcast sockets?

• Not all routers will pass Multicast sockets.

• Multicasting may not be supported on your network.

• TTLs limit a packets spread.

• TTL = max # of routers a packet is allowed to cross.

Page 4: Multicast Sockets What is a multicast socket? –unicast sockets provide a point to point connection. There is one sender and one receiver. –Multicast sockets.

What are some Applications for Mcast?

• appliances can look for a lookup server MCast.– suppose I plug in a PNP printer

• MCast is good for discovery

• Unicast is good for correspondance.

• Etherswitch does a kind of routing that protects net legs from traffic.

Page 5: Multicast Sockets What is a multicast socket? –unicast sockets provide a point to point connection. There is one sender and one receiver. –Multicast sockets.

IP multicast service model

• RFC1112 : Host Extensions for IP Multicasting - 1989• Senders transmit IP datagrams to a "host group"

• Members of host group could be present anywhere in the Internet

• Members join and leave the group and indicate this to the routers

• Senders and receivers are distinct

• Routers listen to all multicast addresses and use multicast routing protocols to manage groups

Page 6: Multicast Sockets What is a multicast socket? –unicast sockets provide a point to point connection. There is one sender and one receiver. –Multicast sockets.

IP multicast group address

• receivers can be anywhere• Class D address space

– high-order three 3bits are set– 224.0.0.0 ~ 239.255.255.255

• Some well-known address have been designated – RFC1700– 224.0.0.0 ~ 224.0.0.25

Page 7: Multicast Sockets What is a multicast socket? –unicast sockets provide a point to point connection. There is one sender and one receiver. –Multicast sockets.

Link-Layer Multicast Addresses

0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 1 1 1 1 0 0

1 1 1 0 28 bits

23 bits

IP multicast address

Group bit

Ethernet and other LANs using 802 addresses:

LAN multicast address

Lower 23 bits of Class D address are inserted into the lower 23 bits of MAC address (see RFC 1112)

0x01005e

Page 8: Multicast Sockets What is a multicast socket? –unicast sockets provide a point to point connection. There is one sender and one receiver. –Multicast sockets.

Multicast Announcement (Lookup initiated discovery)

Discoverer Lookup Service

1. Announcements (sent via UDP

Multicast) IP Address - 224.0.1.84port:4160

3. Response Message(Sent via TCP unicast)

2. Request Message (sent via TCP unicast)

Page 9: Multicast Sockets What is a multicast socket? –unicast sockets provide a point to point connection. There is one sender and one receiver. –Multicast sockets.

Lookup Service

Service Provider

Service Object

Service Attributes

Client

Lookup Service

Service Object

Service Attributes

3. Interact with service

2. Gets Service Proxy

1. Query the Lookup service

Page 10: Multicast Sockets What is a multicast socket? –unicast sockets provide a point to point connection. There is one sender and one receiver. –Multicast sockets.

Source distribution tree

Receiver 1

E

BA D F

SourceNotation: (S, G) S = Source G = Group

C

Receiver 2

S

R R

Page 11: Multicast Sockets What is a multicast socket? –unicast sockets provide a point to point connection. There is one sender and one receiver. –Multicast sockets.

Protocol Characteristics

• Multicast UDP to IP - 224.0.1.84, port 4160

• Interval - 120 secs.

• Multicast Packet length never to exceed 512 bytes.

Page 12: Multicast Sockets What is a multicast socket? –unicast sockets provide a point to point connection. There is one sender and one receiver. –Multicast sockets.

Etherswitch/mcast

• Etherswitch passes all mcast traffic through.

• Etherswitch isolates only unicast traffic.

• Ethernet 10 mbps – 100 mpbs 1Gbps 10 Gb/s.

• Now we can do VIDEO on the Ethernet.

Page 13: Multicast Sockets What is a multicast socket? –unicast sockets provide a point to point connection. There is one sender and one receiver. –Multicast sockets.

Broadcast Video

• CCIR-601 Standard Video– 720-x480 pixels at 16 bits per PEL at 30

Frames per second.– 160 Mb/s, uncompressed.– Suppose you don’t use a video camera to make

video!

Page 14: Multicast Sockets What is a multicast socket? –unicast sockets provide a point to point connection. There is one sender and one receiver. –Multicast sockets.

What is video?

• Image sequences + audio

• How can I make image sequences?

• Screen capture….are almost NOISE FREE.

• Inter-frame coherence. Difference frames

• can be coded efficiently.

Page 15: Multicast Sockets What is a multicast socket? –unicast sockets provide a point to point connection. There is one sender and one receiver. –Multicast sockets.

Java Net ClassesClass Description

DatagramPacket This class represents a datagram packet.

DatagramSocket This class represents a socket for sending and receiving datagram packets.

InetAddress This class represents an Internet Protocol (IP) address.

MulticastSocket The multicast datagram socket class is useful for sending and receiving IP multicast packets.

ServerSocket This class implements server sockets.

Socket This class implements client sockets (also called just "sockets").

URL A pointer to a "resource" on the World Wide Web.

URLConnection The superclass of all classes that represent a communications link between an application and a URL.

Page 16: Multicast Sockets What is a multicast socket? –unicast sockets provide a point to point connection. There is one sender and one receiver. –Multicast sockets.

Class InetAddresspublic boolean equals(Object obj);

public byte[] getAddress();public static InetAddress[] getAllByName(String host);public static InetAddress getByName(String host);public String getHostName();public static InetAddress getLocalHost();

public int hashCode();public String toString();

This class represents an Internet Protocol (IP) address.

Applications should use the methods getLocalHost(), getByName(), or

getAllByName() to create a new InetAddress instance.

Page 17: Multicast Sockets What is a multicast socket? –unicast sockets provide a point to point connection. There is one sender and one receiver. –Multicast sockets.

IP Multicast in Java

• Java has a Multicast Socket Class• Use it to “join” a multicast group.

MulticastSocket s = null;InetAddress group = null;

try { group = InetAddress.getByName(“227.1.2.3”); s = new MulticastSocket(5555); s.joinGroup(group);} catch (UnknownHostException e) { } catch (IOException e) {

}

Page 18: Multicast Sockets What is a multicast socket? –unicast sockets provide a point to point connection. There is one sender and one receiver. –Multicast sockets.

IP Multicast in Java

• Receive DatagramPackets on a MulticastSocket

DatagramPacket recv = new DatagramPacket(buf, buf.length);try { s.receive(recv);} catch (IOException e) { System.out.println("mcastReceive: " + e.toString()); return;}// get messageString msg = new String(recv.getData(), recv.getOffset(), recv.getLength());

Page 19: Multicast Sockets What is a multicast socket? –unicast sockets provide a point to point connection. There is one sender and one receiver. –Multicast sockets.

IP Multicast in Java

• To send, just send a DatagramPacket to the multicast address, port (no need to use a MulticastSocket, although you could)

group = InetAddress.getByName(“227.1.2.3”);s = new DatagramSocket();

DatagramPacket snd = new DatagramPacket(buf, buf.length, group, 5555);

try { s.send(snd);} catch (IOException e) { System.out.println("mcastSend: " + e.toString()); return;}

Page 20: Multicast Sockets What is a multicast socket? –unicast sockets provide a point to point connection. There is one sender and one receiver. –Multicast sockets.

Class Socket// Constructors (partial list)public Socket()public Socket(InetAddress address, int port);public Socket(String host, int port);

// Methods (partial list)public void close();

public InetAddress getInetAddress(); public int getLocalPort();

public InputStream getInputStream();public OutputStream getOutputStream();

public int getPort(); public String toString();

Page 21: Multicast Sockets What is a multicast socket? –unicast sockets provide a point to point connection. There is one sender and one receiver. –Multicast sockets.

Class Socket

• This class implements client sockets (also called just sockets). A socket is a end point for communication between two machines.

• The actual work of the socket is performed by an instance of the SocketImpl class.

• It is possible to modify some TCP parameters:– SO_LINGER – SO_TIMEOUT– TCP_NODELAY

– Enable/disable TCP_NODELAY (disable/enable Nagle's algorithm).

Page 22: Multicast Sockets What is a multicast socket? –unicast sockets provide a point to point connection. There is one sender and one receiver. –Multicast sockets.

Class ServerSocket

// Constructors (partial list)

public ServerSocket(int port);public ServerSocket(int port, int count);

// Methods (partial list)

public Socket accept();public void close();

public InetAddress getInetAddress();public int getLocalPort();

public String toString();

Page 23: Multicast Sockets What is a multicast socket? –unicast sockets provide a point to point connection. There is one sender and one receiver. –Multicast sockets.

Class ServerSocket

• A ServerSocket waits for requests to come in over the network. It performs some operation based on that request, and then possibly returns a result to the requester.

• The actual work of the ServerSocket is performed by an instance of the SocketImpl class.

• The abstract class SocketImpl is a common superclass of all classes that actually implement sockets. It is used to create both client and server sockets.

• A plain socket implements the SocketImpl methods exactly as

described, without attempting to go through a firewall or proxy.

Page 24: Multicast Sockets What is a multicast socket? –unicast sockets provide a point to point connection. There is one sender and one receiver. –Multicast sockets.

UDP Based Applications

• UDP - unreliable packet based delivery service.

• The basic unit of transfer is called a Datagram. Datagrams are small, fixed-length messages.

• Datagram based services do have some advantages:

– Speed

– Message-oriented service.

Page 25: Multicast Sockets What is a multicast socket? –unicast sockets provide a point to point connection. There is one sender and one receiver. –Multicast sockets.

Datagrams

• Datagram packets - implement a connectionless, packet based, delivery service.

• messages are routed based packet content.

• Multiple packets sent from one machine to another might be routed differently, and might arrive in any order.

• Packets may be lost or duplicated during transit.

• The class DatagramPacket represents a datagram in Java.

Page 26: Multicast Sockets What is a multicast socket? –unicast sockets provide a point to point connection. There is one sender and one receiver. –Multicast sockets.

Class DatagramPacket

//Constructorspublic DatagramPacket(byte ibuf[], int ilength);public DatagramPacket( byte ibuf[], int ilength, InetAddress iaddr, int iport);

// Methodspublic synchronized InetAddress getAddress();public synchronized int getPort();public synchornized byte[] getData();int getLength();

void setAddress(InetAddress iaddr);void setPort(int iport);void setData(byte ibuf[]);void setLength(int ilength);

Page 27: Multicast Sockets What is a multicast socket? –unicast sockets provide a point to point connection. There is one sender and one receiver. –Multicast sockets.

Class DatagramSocket

• class represents a socket for sending/receiving datagrams.

• Addressing information in the packet header.

• A socket are bound to an address• There is no special datagram server socket

class.• packets can be lost, timeouts are important.

Page 28: Multicast Sockets What is a multicast socket? –unicast sockets provide a point to point connection. There is one sender and one receiver. –Multicast sockets.

Class DatagramSocket

// ConstructorsDatagramSocket() DatagramSocket(int port)DatagramSocket(int port, InetAddress iaddr) // Methodsvoid close() InetAddress getLocalAddress() int getLocalPort() int getSoTimeout() void receive(DatagramPacket p) void send(DatagramPacket p) setSoTimeout(int timeout)

Page 29: Multicast Sockets What is a multicast socket? –unicast sockets provide a point to point connection. There is one sender and one receiver. –Multicast sockets.

Echo Services

• A common network service is an echo server

• An echo server simply sends packets back to the sender

• A client creates a packet, sends it to the server, and waits for a response.

• Echo services can be used to test network connectivity and performance.

• There are typically different levels of echo services. Each provided by a different layer in the protocol stack.

Page 30: Multicast Sockets What is a multicast socket? –unicast sockets provide a point to point connection. There is one sender and one receiver. –Multicast sockets.

UDPEchoClient.javaimport java.net.*; import java.io.*; import java.util.*;

public class UDPEchoClient { static int echoPort = 7; static int msgLen = 16; static int timeOut=1000;

public static void main(String argv[]) { try { DatagramSocket sock = new DatagramSocket(); DatagramPacket pak; byte msg[] = new byte[msgLen];

InetAddress echoHost = InetAddress.getByName(argv[0]); pak = new DatagramPacket(msg,msgLen,echoHost,echoPort);

sock.send(pak); sock.setSoTimeout(timeOut); sock.receive(pak); } catch (InterruptedIOException e) {System.out.println("Timeout");} catch (Exception e) {} }}