catch(IOException e) fail(e, "Exception creating server
socket");
System.out.println("Server: listening on port" port);
This.start();
}
/*
下面為服務器監聽線程的主程序。該線程一直循環執行,監聽并接受客戶機發出的連接
請求。對每一個連接,均產生一個連接對象與之對應,通過Socket
通道進行通信。*/
public void run()
{
try
{
while(true)
{
Socket client_socket = listen_socket.accept();
Connection c = new Connection(client_socket);
}
}
catch(IOException e) fail(e,"Exception while listening for
connections")
}
// 啟動服務器主程序
public static void main(String args[])
{
int port = 0;
if (args.length == 1)
{
try port = Integer.parseInt(args[0]);
catch(NumberFormatException e) port = 0;
}
文章來源于領測軟件測試網 http://www.kjueaiud.com/