日期:2014-05-20 浏览次数:20954 次
ServerSocketFactory factory = ServerSocketFactory.getDefault();
ServerSocket serverSocket = factory.createServerSocket(8888);
Socket socket = serverSocket.accept();
OutputStream out = socket.getOutputStream();
InputStream in = socket.getInputStream();
// 用in和out做一些事情
// 。。。
// 关闭
socket.getOutputStream().close();
socket.getInputStream().close();// 这句抛SocketException socket is closed
socket.close();
serverSocket.close();