Guergeiro / distributed-systems-2019

This repository contains our practical project for the class of distributed systems
https://cepos-e-mabecos.github.io/distributed-systems-2019/docs
MIT License
0 stars 2 forks source link

Added support for Multicasting #3

Closed Guergeiro closed 4 years ago

Guergeiro commented 4 years ago

To test this, you need to pass arguments that contain the MulticastPort, MulticastAddress and ServerPort. If you want two instances of the Server just run it two times and change the ServerPort so that they are different (Multicast Settings remain).

A Client is given bellow:

Integer port = 5000;
String address = "230.1.1.1";

DatagramSocket socket = null;
InetAddress host = null;
DatagramPacket request = null;

try {
  socket = new DatagramSocket();
  host = InetAddress.getByName(address);

  byte message[] = "Vou enviar esta mensagem aos servidores".getBytes();

  request = new DatagramPacket(message, message.length, host, port);

  socket.send(request);
} catch (IOException e) {
  System.out.println(e.getMessage());
}

Place p1 = new Place("3500", "Viseu");

try {
  PlacesListInterface p2 = (PlacesListInterface) Naming.lookup("rmi://127.0.0.1:6000/placelist");
  p2.addPlace(p1);

  System.out.println(p2.getPlace("3500").getLocality());
} catch (MalformedURLException | RemoteException | NotBoundException e) {
  System.out.println(e.getMessage());
}