new Server(port);
}
// End of the main
} // End of
Server class
//以下定義了Connection
類,它是用來處理與客戶機的所有通信的線程。
class Connection extends Thread
{
protected Socket client;
protected DataInputStream in;
protected PrintStream out;
// 初始化通信流并啟動線程
public Connection(Socket client_socket)
{
client = client_socket;
try
{
in = new DataInputStream(client.getinputStream());
out = new PrintStream(client.getOutputStream());
}
catch(IOException e)
{
try client.close();
catch(IOException e2);
System.err.println("Exception while getting socket
streram: " e);
Return;
}
this.start;
}
延伸閱讀
文章來源于領測軟件測試網 http://www.kjueaiud.com/