import java.net.*;
import java.io.IOException;
public class ServerSocketTest
{
public static void main(String[] args)
{
ServerSocket server=null;
try
{
server=new ServerSocket(8888);
System.out.println("成功创建服务器套接字");
while(true)
{
System.out.println("处于等待客户机连接状态");
Socket socket=server.accept();
System.out.println("和客户机建立连接");
}
}
catch(IOException e)
{
System.out.println("服务器套接字操作发生异常");
}
finally
{
try
{
if(server!=null)
{
server.close();
}
}
catch (IOException e)
{
System.out.println("关闭服务器套接字发生异常");
}
}
}
}