David Wu 8 years ago
commit 42a5d8ddc4

@ -29,20 +29,16 @@ public class NetworkInterface {
private Set<ClientAddress> clientsAddresses;
private MatchTable matchTable;
private InetAddress groupAddress;
private int groupPort;
public NetworkInterface(){
this.clientsAddresses = new HashSet<>();
this.matchTable = new MatchTable();
this.scheduler = new Timer(true);
try {
this.groupAddress = InetAddress.getLocalHost(); //InetAddress.getByName("239.0.0.1");
this.groupPort = 4941;
this.serverSocket = new DatagramSocket(3779);
startBroadcast(5000);
scheduleFlush(30000);
scheduleFlush(70000);
this.run();
} catch (IOException e) {
System.err.println("Error listening on port: " + this.serverSocket.getLocalPort() + ".");
@ -73,7 +69,8 @@ public class NetworkInterface {
byte[] message = encoder.encode(new HostGamesRequest(games));
System.out.println(LocalDateTime.now() + ": Sending " + games.size() + " game/s");
for(ClientAddress address: clientsAddresses) {
serverSocket.send(new DatagramPacket(message, message.length, InetAddress.getByName(address.getIp()), groupPort));
System.out.println("sending to: " + address.getIp());
serverSocket.send(new DatagramPacket(message, message.length, InetAddress.getByName(address.getIp()), 4941));
}
} catch (InvalidMessageException | IOException e) {
e.printStackTrace();
@ -90,6 +87,7 @@ public class NetworkInterface {
scheduler.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
System.out.println("flush");
matchTable.getMatchTable().clear();
}
}, period, period);

@ -47,6 +47,7 @@ public class MatchBrowserLobbyInterface extends Observable {
try {
HostGamesRequest message = (HostGamesRequest) hostedGamesRequestDecoder.decode(data);
games = message.getKnownGames();
System.out.println(games);
setChanged();
notifyObservers();
} catch (InvalidMessageException e) {

Loading…
Cancel
Save