ServerSocket server

phptong 2004-11-21 08:31:50
ServerSocket server为什么不能写成ServerSocket server=new ServerSocket;

Socket socket;可以写成Socket socket=new Socket();
...全文
78 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
wushuren 2004-11-21
  • 打赏
  • 举报
回复
ServerSocket
public ServerSocket()
throws IOException
Creates an unbound server socket.

Throws:
IOException - IO error when opening the socket.

--------------------------------------------------------------------------------

ServerSocket
public ServerSocket(int port)
throws IOException
Creates a server socket on a specified port. A port of 0 creates a socket on any free port.
The maximum queue length for incoming connection indications (a request to connect) is set to 50. 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.

If there is a security manager, its checkListen method is called with the port argument as its argument to ensure the operation is allowed. This could result in a SecurityException.


Parameters:
port - the port number, or 0 to use any free port.
Throws:
IOException - if an I/O error occurs when opening the socket.
SecurityException - if a security manager exists and its checkListen method doesn't allow the operation.
See Also:
SocketImpl, SocketImplFactory.createSocketImpl(), setSocketFactory(java.net.SocketImplFactory), SecurityManager.checkListen(int)

--------------------------------------------------------------------------------

ServerSocket
public ServerSocket(int port,
int backlog)
throws IOException
Creates a server socket and binds it to the specified local port number, with the specified backlog. 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 backlog 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.

If there is a security manager, its checkListen method is called with the port argument as its argument to ensure the operation is allowed. This could result in a SecurityException.

The backlog argument must be a positive value greater than 0. If the value passed if equal or less than 0, then the default value will be assumed.



Parameters:
port - the specified port, or 0 to use any free port.
backlog - the maximum length of the queue.
Throws:
IOException - if an I/O error occurs when opening the socket.
SecurityException - if a security manager exists and its checkListen method doesn't allow the operation.
See Also:
SocketImpl, SocketImplFactory.createSocketImpl(), setSocketFactory(java.net.SocketImplFactory), SecurityManager.checkListen(int)

--------------------------------------------------------------------------------

ServerSocket
public ServerSocket(int port,
int backlog,
InetAddress bindAddr)
throws IOException
Create a server with the specified port, listen backlog, and local IP address to bind to. The bindAddr argument can be used on a multi-homed host for a ServerSocket that will only accept connect requests to one of its addresses. If bindAddr is null, it will default accepting connections on any/all local addresses. The port must be between 0 and 65535, inclusive.
If there is a security manager, this method calls its checkListen method with the port argument as its argument to ensure the operation is allowed. This could result in a SecurityException.

The backlog argument must be a positive value greater than 0. If the value passed if equal or less than 0, then the default value will be assumed.



Parameters:
port - the local TCP port
backlog - the listen backlog
bindAddr - the local InetAddress the server will bind to
Throws:
SecurityException - if a security manager exists and its checkListen method doesn't allow the operation.
IOException - if an I/O error occurs when opening the socket.
Since:
JDK1.1
See Also:
SocketOptions, SocketImpl, SecurityManager.checkListen(int)
Method Detail
wushuren 2004-11-21
  • 打赏
  • 举报
回复
看看帮助.

67,512

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧