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是从已完成三路握手的连接队列中取出一个链接,创建一个描述符并返回。
推荐阅读
- dart这编程语言现在发展怎么样了,语法与Java,c#很相似,甚至更简洁
- Java工程师和C++工程师在工作上有啥区别哪个更适合自身发展
- 27岁,转行java的血与泪,该何去何从
- 怎样统计工程中未使用的java类
- 新互联网网站用Java还靠谱么对比Php,Python,Ruby的话
- 我想学java和安卓软件开发?
- 学计算机专业,java那些和网站开发选台式还是笔记本好
- JAVA设计思路
- 本人大专毕业一年,想要去培训,定了JAVAEE和安卓两个方向,应该学那个纠结,求帮助
- 从未接触过软件测试和java,可以学习主要是自学这两种其一吗
