当前位置: 技术问答>java相关
ServerSocket的一个小问题
来源: 互联网 发布时间:2015-03-21
本文导语: Syntax 2 public ServerSocket( int port, int backlog ) throws IOException Parameters port the specified port, or 0 to use any free port. backlog the maximum length of the queue. Description Creates a server socket and binds it to the specified...
Syntax 2
public ServerSocket( int port, int backlog ) throws IOException
Parameters
port
the specified port, or 0 to use any free port.
backlog
the maximum length of the queue.
Description
Creates a server socket and binds it to the specified local port number. A port number of 0 creates a socket on any free port.
The maximum queue length for incoming connection indications (a request to connect) is set to the count parameter. If a connection indication arrives when the queue is full, the connection is refused.
If the application has specified a server socket factory, that factory's createSocketImpl method is called to create the actual socket implementation. Otherwise a "plain" socket is created.
Exceptions
IOException if an I/O error occurs when opening the socket
小弟有一不解,到底ServerSocket()中的第二个参数时干吗用的?简单吧,
public ServerSocket( int port, int backlog ) throws IOException
Parameters
port
the specified port, or 0 to use any free port.
backlog
the maximum length of the queue.
Description
Creates a server socket and binds it to the specified local port number. A port number of 0 creates a socket on any free port.
The maximum queue length for incoming connection indications (a request to connect) is set to the count parameter. If a connection indication arrives when the queue is full, the connection is refused.
If the application has specified a server socket factory, that factory's createSocketImpl method is called to create the actual socket implementation. Otherwise a "plain" socket is created.
Exceptions
IOException if an I/O error occurs when opening the socket
小弟有一不解,到底ServerSocket()中的第二个参数时干吗用的?简单吧,
|
int backlog:当连接请求到达时,会被排队,这就称为积压(backlog),当队列满了,就拒绝连接请求,任何新的连接请求都将被拒绝。
如果不指定积压backlog的大小,backlog默认值为50。
如果不指定积压backlog的大小,backlog默认值为50。