ServerSocket listener = new ServerSocket(Main.ports.get(peerIndex));
receiver = new ReceiveManager(listener, this);
/* The normal peers won't create other senders */
if (peerIndex != Main.rootPeer)
peerSender = new Sender(Main.IPAdresses.get(Main.rootPeer),
Main.ports.get(Main.rootPeer));
else {
senders = new ArrayList<Sender>(Main.peerCount - 1);
/* Create the sender threads */
for (int i = 0; i < Main.peerCount; i++) {
if (i == peerIndex)
continue;
senders.add(new Sender(Main.IPAdresses.get(i), Main.ports.get(i)));
}
}
} catch (Exception e) {
System.out.println("Unable to start sockets");
e.printStackTrace();