0
我發現了一個練習(它不是作業或任何東西,不用擔心):評論下面的代碼。問題是,我不知道這段代碼做了什麼。迄今爲止,我發表了我的評論。那是對的嗎 ?Socket和Thread,這段代碼做了什麼?
public class A {
private ServerSocket a;
// constructor
public A (int p) {
a = new ServerSocket(p); // create a server socket on port p.
while(true) { // infinite loop
Socket c = a.accept(); // accept the connection from the client.
Thread th = new Thread(new B(c)); // huh... wtf ? Is that a thread declaration with the
//runnable interface ?
//I have no idea. c socket is copied
// in B class field by B constructor.
}
}
public class B implements Runnable {
private Socket a;
// constructor
public B(Socket aa) {
a = aa; // copying a socket.
}
public void run() { // overide run methode from runnable ? I don't remember, there is a thing with run...
/// Question from the exercice : what should i put here ?
}
}
thx很多。我會尋找更多關於跑步方法的信息,因爲我忘了,但你基本上回答了我的所有問題。謝謝 – Csi