Udp Multicast
Udp Multicast
Server:
Server receives line of text
Capitalizes all the letters
Sends modified line to client
Client:
Receives line of text
Displays
write reply to
serverSocket
specifying read datagram from
client address, clientSocket
port number close
clientSocket
inFromUser
input
stream
Client
Process
process Input: receives
packet (recall
Output: sends thatTCP received
packet (recall “byte stream”)
receivePacket
sendPacket
that TCP sent UDP UDP
“byte stream”)
packet packet
client
clientSocket UDP
socket UDP
socket
class UDPClient {
public static void main(String args[]) throws Exception
{
Create
input stream BufferedReader inFromUser =
Create new BufferedReader(new InputStreamReader(System.in));
client socket
DatagramSocket clientSocket = new DatagramSocket();
Translate
hostname to IP InetAddress IPAddress = InetAddress.getByName("hostname");
address using DNS
byte[] sendData = new byte[1024];
byte[] receiveData = new byte[1024];
String modifiedSentence =
new String(receivePacket.getData());
class UDPServer {
public static void main(String args[]) throws Exception
Create {
datagram socket
at port 9876 DatagramSocket serverSocket = new DatagramSocket(9876);
while(true)
{
Create space for
received datagram DatagramPacket receivePacket =
new DatagramPacket(receiveData, receiveData.length);
Receive serverSocket.receive(receivePacket);
datagram
H. Fauconnier M2-Internet Java 9
Example: Java server (UDP), cont
String sentence = new String(receivePacket.getData());
Get IP addr
port #, of InetAddress IPAddress = receivePacket.getAddress();
sender
int port = receivePacket.getPort();
sendData = capitalizedSentence.getBytes();
Create datagram
to send to client DatagramPacket sendPacket =
new DatagramPacket(sendData, sendData.length, IPAddress,
port);
Write out
datagram serverSocket.send(sendPacket);
to socket }
}
} End of while loop,
loop back and wait for
another datagram
H. Fauconnier M2-Internet Java 10
UDP observations & questions
Both client server use DatagramSocket
Dest IP and port are explicitly attached to segment.
What would happen if change both clientSocket and
serverSocket to “mySocket”?
Can the client send a segment to server without
knowing the server’s IP address and/or port
number?
Can multiple clients use the server?
try {
InetAddress ia =
InetAddress.getByName("www.liafa.jussieu.fr");
int port = 7;// existe-t-il?
DatagramPacket dp = new DatagramPacket(data,
data.length, ia, port);
}
catch (IOException ex)
}
} // end lancer
}
try {
BufferedReader userInput = new BufferedReader(new
InputStreamReader(System.in));
while (true) {
if (stopped) return;
String theLine = userInput.readLine();
if (theLine.equals(".")) break;
byte[] data = theLine.getBytes();
DatagramPacket output
= new DatagramPacket(data, data.length, server, port);
socket.send(output);
Thread.yield();
}
} // end try
catch (IOException ex) {System.err.println(ex); }
} // end run
}
H. Fauconnier
M2-Internet Java 29
Broadcast Routing
Deliver packets from srce to all other nodes
Source duplication is inefficient:
duplicate
duplicate
R1 creation/transmission R1
duplicate
R2 R2
R3 R4 R3 R4
source in-network
duplication duplication
B B
c c
D D
F E F E
G G
(a) Broadcast initiated at A (b) Broadcast initiated at D
A A
3
B B
c c
4
2
D D
F E F E
1 5
G G
(a) Stepwise construction (b) Constructed spanning
of spanning tree tree
H. Fauconnier M2-Internet Java 4-33
Multicast
Groupe: adresse IP de classe D
Un hôte peut joindre un groupe
…we first look at basic approaches, then specific protocols adopting these
approaches
S: source LEGEND
R1 2
1 R4 router with attached
group member
R2 5
router with no attached
3 4
R5 group member
R3 6 i link used for forwarding,
R6 R7 i indicates order link
added by algorithm
S: source LEGEND
LEGEND
Dense: Sparse:
group members densely # networks with group members
packed, in “close” proximity. small wrt # interconnected networks
bandwidth more plentiful group members “widely dispersed”
bandwidth not plentiful
Dense Sparse:
group membership by no membership until
routers assumed until routers explicitly join
routers explicitly prune receiver- driven
data-driven construction construction of mcast
on mcast tree (e.g., RPF) tree (e.g., center-based)
bandwidth and non- bandwidth and non-group-
group-router processing router processing
profligate conservative