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;
}
文章来源于领测软件测试网 https://www.ltesting.net/