JAVA 的 ServerSocket 在accept()的时候到底发生了啥?

你可以看源代码:/** * Listens for a connection to be made to this socket and accepts * it. The method blocks until a connection is made. * * \u0026lt;p\u0026gt;A new Socket \u0026lt;code\u0026gt;s\u0026lt;/code\u0026gt; is created and, if there * is a security manager, * the security manager\u0026#39;s \u0026lt;code\u0026gt;checkAccept\u0026lt;/code\u0026gt; method is called * with \u0026lt;code\u0026gt;s.getInetAddress().getHostAddress()\u0026lt;/code\u0026gt; and * \u0026lt;code\u0026gt;s.getPort()\u0026lt;/code\u0026gt; * as its arguments to ensure the operation is allowed. * This could result in a SecurityException. * * @exception IOException if an I/O error occurs when waiting for a * connection. * @exception SecurityException if a security manager exists and its * \u0026lt;code\u0026gt;checkAccept\u0026lt;/code\u0026gt; method doesn\u0026#39;t allow the operation. * @exception SocketTimeoutException if a timeout was previously set with setSoTimeout and * the timeout has been reached. * @exception java.nio.channels.IllegalBlockingModeException * if this socket has an associated channel, the channel is in * non-blocking mode, and there is no connection ready to be * accepted * * @return the new Socket * @see SecurityManager#checkAccept * @revised 1.4 * @spec JSR-51 */ public Socket accept() throws IOException {\tif (isClosed())\t throw new SocketException("Socket is closed");\tif (!isBound())\t throw new SocketException("Socket is not bound yet");\tSocket s = new Socket((SocketImpl) null);\timplAccept(s);\treturn s; }accept()方法内部生成的
■网友
明显是新生成一个socket么。accept是从已完成三路握手的连接队列中取出一个链接,创建一个描述符并返回。


    推荐阅读