Thread and Runnable passage of objects
Hi all,
I'm having a lit of trouble to put this working, I have a class responsible for the network communication of my program.
It has to accept incoming request and deal with them properly.
For that I have the following code:
publicvoid receive(){
System.out.println("Receive start");
// Server
Runnable srv =new Runnable(){
publicvoid run(){
Socket s;
try{
while (true){
ss =new ServerSocket(7000);
System.out.println("Waiting for incoming connections ...");
s=ss.accept();
//Takes care of the accepted calls
Runnable cli =new Runnable(){
private Socket soc;
publicvoid run(){
System.out.println("Client " + soc.getInetAddress().toString() +"Connected");
}
};
Thread c =new Thread(cli);
c.run();
}
}catch(Exception err){
System.out.println("Burn to the ground");
};
}
};
Thread r =new Thread(srv,"srv");
r.run();
System.out.println("Receive end");
}
If I try to use the same var it states it needs to be final, I'm unable to create method to put into there.
Is it the best way the create a second class extending thread?
Thanks to all
Alex

