码迷,mamicode.com
首页 > 其他好文 > 详细

第三章 ServerSpcket用法详解

时间:2016-05-22 21:25:28      阅读:226      评论:0      收藏:0      [点我收藏+]

标签:

3.1 构造ServerSocket

  ServerSocket的构造方法如下:

技术分享
 1 ServerSocket() 
 2 //Creates an unbound server socket.
 3  
 4 ServerSocket(int port) 
 5 //Creates a server socket, bound to the specified port.
 6  
 7 ServerSocket(int port, int backlog) 
 8 //Creates a server socket and binds it to the specified local port number, with the 
 9 //specified backlog.
10  
11 ServerSocket(int port, int backlog, InetAddress bindAddr) 
12 //Create a server with the specified port, listen backlog, and local IP address to 
13 //bind to. 
View Code

  参数port指定服务器需要绑定的端口(监听端口),参数backlog指定客户连接请求队列的长度,参数bindAddr指定服务器需要绑定的IP地址。

  参数port设为0时,由系统自动分配端口。

  当队列中的连接请求达到了队列的最大容量时,服务器进程所在的主机会拒绝新的连接请求。当服务器通过ServerSocket.accept()方法从队列取出连接请求时,队列腾出空位,新的连接请求加入队列。

  对于客户机进程,如果他发出的连接请求被加入到服务器队列,则说明连接成功,客户机Socket正常返回,否则抛出ConnectionException异常。

第三章 ServerSpcket用法详解

标签:

原文地址:http://www.cnblogs.com/wuchaodzxx/p/5517677.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!