Ciao a tutti. sto realizzando un tracker per un protocollo di file sharing inspirato a BitTorrent. Per gestire lo swarm uso due thread
- un thread per la gestione dello swarm
- un thread per il controllo della presenza dei peer
Ho una classe chiamata TCPTracker nella quale uso una socket ssl in ascolto per tutti i peer che si collegano al tracker, questi ultimi si identificano mediante il riferimento al descrittore del file che intendono condividere (che è anche l'identificatore dello swarm) e dopodichè vengono assegnati ad un apposito servizio che gestisce le loro richieste (TCPTrackerService che implementa l'interfaccia Runnable). Al costruttore del servizio passo il riferimento allo socket e da questa cerco di riottenere gli input e gli output stream ottenendo un StreamCorruptedException.
Parte della classe TCPTracker
while (true) {
try {
if (active) {
socket = server.accept();
ObjectInputStream in = new ObjectInputStream(socket.getInputStream());
[...]
ObjectOutputStream out = new ObjectOutputStream(socket.getOutputStream());
[...]
if (found) {
out.writeUTF("Welcome OK");
out.flush();
out.close();
trackMan.getSwarms().get(index).addPeer(peer);
----------------------> TCPTrackerService tmp = new TCPTrackerService(socket, trackMan.getSwarms().get(index));
tcpTrackConnServices.execute(tmp);
} else {
out.writeUTF("Bad ERROR");
out.flush();
}
}
[...]
} catch (IOException ex) {
ex.printStackTrace();
} catch (ClassNotFoundException ignore) {
}
}
Costruttore della classe TCPTrackerService
public TCPTrackerService(Socket socket, Swarm swarmRef) throws IOException {
this.socket = socket;
this.inStream = new ObjectInputStream(socket.getInputStream()); <-----------------
this.outStream = new ObjectOutputStream(socket.getOutputStream());
this.swarmRef = swarmRef;
active = true;
}
La freccia indica il punto dove ottengo l'eccezione. Mi sapreste dire il perchè? Grazie infinite.

Rispondi quotando