如何创建侦听所有ip地址,和所有端口的socket??

shen_hong_fu 2002-04-22 11:55:53
如何创建侦听所有ip地址,和所有端口的socket??
...全文
251 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
telenths 2002-04-23
  • 打赏
  • 举报
回复
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.
**************************************************************public用 ServerSocket(int port)
把 port 设为 0 就行了

62,615

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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