分享
 
 
 

java.net.ServerSocket翻译

王朝java/jsp·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<!--NewPage-->

<HTML>

<HEAD>

<!-- Generated by javadoc (build 1.4.2-rc) on Fri Jun 13 00:14:24 PDT 2003 -->

<TITLE>

ServerSocket (Java 2 Platform SE v1.4.2)

</TITLE>

<META NAME="keywords" CONTENT="java.net.ServerSocket class">

<META NAME="keywords" CONTENT="bind()">

<META NAME="keywords" CONTENT="getInetAddress()">

<META NAME="keywords" CONTENT="getLocalPort()">

<META NAME="keywords" CONTENT="getLocalSocketAddress()">

<META NAME="keywords" CONTENT="accept()">

<META NAME="keywords" CONTENT="implAccept()">

<META NAME="keywords" CONTENT="close()">

<META NAME="keywords" CONTENT="getChannel()">

<META NAME="keywords" CONTENT="isBound()">

<META NAME="keywords" CONTENT="isClosed()">

<META NAME="keywords" CONTENT="setSoTimeout()">

<META NAME="keywords" CONTENT="getSoTimeout()">

<META NAME="keywords" CONTENT="setReuseAddress()">

<META NAME="keywords" CONTENT="getReuseAddress()">

<META NAME="keywords" CONTENT="toString()">

<META NAME="keywords" CONTENT="setSocketFactory()">

<META NAME="keywords" CONTENT="setReceiveBufferSize()">

<META NAME="keywords" CONTENT="getReceiveBufferSize()">

<LINK REL ="stylesheet" TYPE="text/css" HREF="../../stylesheet.css" TITLE="Style">

<SCRIPT type="text/javascript">

function windowTitle()

{

parent.document.title="ServerSocket (Java 2 Platform SE v1.4.2)";

}

</SCRIPT>

</HEAD>

<BODY BGCOLOR="white" onload="windowTitle();">

<!-- ========= START OF TOP NAVBAR ======= -->

<A NAME="navbar_top"><!-- --></A>

<A HREF="#skip-navbar_top" title="Skip navigation links"></A>

<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY="">

<TR>

<TD COLSPAN=3 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">

<A NAME="navbar_top_firstrow"><!-- --></A>

<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY="">

<TR ALIGN="center" VALIGN="top">

<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A>&nbsp;</TD>

<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A>&nbsp;</TD>

<TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT>&nbsp;</TD>

<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="class-use/ServerSocket.html"><FONT CLASS="NavBarFont1"><B>Use</B></FONT></A>&nbsp;</TD>

<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>

<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>

<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../index-files/index-1.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>

<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>

</TR>

</TABLE>

</TD>

<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>

<b>Java<sup><font size=-2>TM</font></sup>&nbsp;2&nbsp;Platform<br>Std.&nbsp;Ed. v1.4.2</b></EM>

</TD>

</TR>

<TR>

<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">

&nbsp;<A HREF="../../java/net/PasswordAuthentication.html" title="class in java.net"><B>PREV CLASS</B></A>&nbsp;

&nbsp;<A HREF="../../java/net/Socket.html" title="class in java.net"><B>NEXT CLASS</B></A></FONT></TD>

<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">

<A HREF="../../index.html" target="_top"><B>FRAMES</B></A> &nbsp;

&nbsp;<A HREF="ServerSocket.html" target="_top"><B>NO FRAMES</B></A> &nbsp;

&nbsp;<SCRIPT type="text/javascript">

<!--

if(window==top) {

document.writeln('<A HREF="../../allclasses-noframe.html"><B>All Classes</B></A>');

}

//-->

</SCRIPT>

<NOSCRIPT>

<A HREF="../../allclasses-noframe.html"><B>All Classes</B></A>

</NOSCRIPT>

</FONT></TD>

</TR>

<TR>

<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">

SUMMARY:&nbsp;NESTED&nbsp;|&nbsp;FIELD&nbsp;|&nbsp;<A HREF="#constructor_summary">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_summary">METHOD</A></FONT></TD>

<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">

DETAIL:&nbsp;FIELD&nbsp;|&nbsp;<A HREF="#constructor_detail">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_detail">METHOD</A></FONT></TD>

</TR>

</TABLE>

<A NAME="skip-navbar_top"></A>

<!-- ========= END OF TOP NAVBAR ========= -->

<HR>

<!-- ======== START OF CLASS DATA ======== -->

<H2>

<FONT SIZE="-1">

java.net</FONT>

<BR>

Class ServerSocket</H2>

<PRE>

<A HREF="../../java/lang/Object.html" title="class in java.lang">java.lang.Object</A>

<IMG SRC="../../resources/inherit.gif" ALT="extended by"><B>java.net.ServerSocket</B>

</PRE>

<DL>

<DT><B>Direct Known Subclasses:</B> <DD><A HREF="../../javax/net/ssl/SSLServerSocket.html" title="class in javax.net.ssl">SSLServerSocket</A></DD>

</DL>

<HR>

<DL>

<DT>public class <B>ServerSocket</B><DT>extends <A HREF="../../java/lang/Object.html" title="class in java.lang">Object</A></DL>

<P>

This class implements server sockets. A server socket waits for

requests to come in over the network. It performs some operation

based on that request, and then possibly returns a result to the requester.

该类实现了服务器套桔字,它等待来自网络的请求,根据请求来执行某些操作,然后可能将结果返回给请求者。

<p>

The actual work of the server socket is performed by an instance

of the <code>SocketImpl</code> class. An application can

change the socket factory that creates the socket

implementation to configure itself to create sockets

appropriate to the local firewall.

服务器套接字的实际工作由SocketImpl类的实例执行。应用程序可以更改创建套接字实现的套接字工厂,配置它来创建适合本地防火墙的套接字。

<P>

<P>

<DL>

<DT><B>Since:</B></DT>

<DD>JDK1.0</DD>

<DT><B>See Also:</B><DD><A HREF="../../java/net/SocketImpl.html" title="class in java.net"><CODE>SocketImpl</CODE></A>,

<A HREF="../../java/net/ServerSocket.html#setSocketFactory(java.net.SocketImplFactory)"><CODE>setSocketFactory(java.net.SocketImplFactory)</CODE></A>,

<A HREF="../../java/nio/channels/ServerSocketChannel.html" title="class in java.nio.channels"><CODE>ServerSocketChannel</CODE></A></DL>

<HR>

<P>

<!-- ======== NESTED CLASS SUMMARY ======== -->

<!-- =========== FIELD SUMMARY =========== -->

<!-- ======== CONSTRUCTOR SUMMARY ======== -->

<A NAME="constructor_summary"><!-- --></A>

<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">

<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">

<TD COLSPAN=2><FONT SIZE="+2">

<B>Constructor Summary</B></FONT></TD>

</TR>

<TR BGCOLOR="white" CLASS="TableRowColor">

<TD><CODE><B><A HREF="../../java/net/ServerSocket.html#ServerSocket()">ServerSocket</A></B>()</CODE>

<BR>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Creates an unbound server socket.

创建无绑定服务器套接字。</TD>

</TR>

<TR BGCOLOR="white" CLASS="TableRowColor">

<TD><CODE><B><A HREF="../../java/net/ServerSocket.html#ServerSocket(int)">ServerSocket</A></B>(int&nbsp;port)</CODE>

<BR>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Creates a server socket, bound to the specified port.

在指定端口创建服务器套接字。</TD>

</TR>

<TR BGCOLOR="white" CLASS="TableRowColor">

<TD><CODE><B><A HREF="../../java/net/ServerSocket.html#ServerSocket(int, int)">ServerSocket</A></B>(int&nbsp;port,

int&nbsp;backlog)</CODE>

<BR>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Creates a server socket and binds it to the specified local port

number, with the specified backlog.

创建服务器套接字并绑定在指定端口,使用指定的队列长度。</TD>

</TR>

<TR BGCOLOR="white" CLASS="TableRowColor">

<TD><CODE><B><A HREF="../../java/net/ServerSocket.html#ServerSocket(int, int, java.net.InetAddress)">ServerSocket</A></B>(int&nbsp;port,

int&nbsp;backlog,

<A HREF="../../java/net/InetAddress.html" title="class in java.net">InetAddress</A>&nbsp;bindAddr)</CODE>

<BR>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Create a server with the specified port, listen backlog, and

local IP address to bind to.

使用指定端口、监听队列和绑定地址创建服务器。</TD>

</TR>

</TABLE>

&nbsp;

<!-- ========== METHOD SUMMARY =========== -->

<A NAME="method_summary"><!-- --></A>

<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">

<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">

<TD COLSPAN=2><FONT SIZE="+2">

<B>Method Summary</B></FONT></TD>

</TR>

<TR BGCOLOR="white" CLASS="TableRowColor">

<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">

<CODE>&nbsp;<A HREF="../../java/net/Socket.html" title="class in java.net">Socket</A></CODE></FONT></TD>

<TD><CODE><B><A HREF="../../java/net/ServerSocket.html#accept()">accept</A></B>()</CODE>

<BR>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Listens for a connection to be made to this socket and accepts

it. 监听发起到此套接字的连接并接受它。</TD>

</TR>

<TR BGCOLOR="white" CLASS="TableRowColor">

<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">

<CODE>&nbsp;void</CODE></FONT></TD>

<TD><CODE><B><A HREF="../../java/net/ServerSocket.html#bind(java.net.SocketAddress)">bind</A></B>(<A HREF="../../java/net/SocketAddress.html" title="class in java.net">SocketAddress</A>&nbsp;endpoint)</CODE>

<BR>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Binds the <code>ServerSocket</code> to a specific address

(IP address and port number).

将ServerSocket绑定到指定地址(IP地址和端口号)。</TD>

</TR>

<TR BGCOLOR="white" CLASS="TableRowColor">

<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">

<CODE>&nbsp;void</CODE></FONT></TD>

<TD><CODE><B><A HREF="../../java/net/ServerSocket.html#bind(java.net.SocketAddress, int)">bind</A></B>(<A HREF="../../java/net/SocketAddress.html" title="class in java.net">SocketAddress</A>&nbsp;endpoint,

int&nbsp;backlog)</CODE>

<BR>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Binds the <code>ServerSocket</code> to a specific address

(IP address and port number).

将ServerSocket绑定到指定地址(IP地址和端口号)。</TD>

</TR>

<TR BGCOLOR="white" CLASS="TableRowColor">

<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">

<CODE>&nbsp;void</CODE></FONT></TD>

<TD><CODE><B><A HREF="../../java/net/ServerSocket.html#close()">close</A></B>()</CODE>

<BR>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Closes this socket.

关闭套接字。</TD>

</TR>

<TR BGCOLOR="white" CLASS="TableRowColor">

<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">

<CODE>&nbsp;<A HREF="../../java/nio/channels/ServerSocketChannel.html" title="class in java.nio.channels">ServerSocketChannel</A></CODE></FONT></TD>

<TD><CODE><B><A HREF="../../java/net/ServerSocket.html#getChannel()">getChannel</A></B>()</CODE>

<BR>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Returns the unique <A HREF="../../java/nio/channels/ServerSocketChannel.html" title="class in java.nio.channels"><CODE>ServerSocketChannel</CODE></A> object

associated with this socket, if any.

如果有,返回同此套接字唯一关联的ServerSocketChannel对象。</TD>

</TR>

<TR BGCOLOR="white" CLASS="TableRowColor">

<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">

<CODE>&nbsp;<A HREF="../../java/net/InetAddress.html" title="class in java.net">InetAddress</A></CODE></FONT></TD>

<TD><CODE><B><A HREF="../../java/net/ServerSocket.html#getInetAddress()">getInetAddress</A></B>()</CODE>

<BR>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Returns the local address of this server socket.

返回此服务器套接字的本地地址。</TD>

</TR>

<TR BGCOLOR="white" CLASS="TableRowColor">

<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">

<CODE>&nbsp;int</CODE></FONT></TD>

<TD><CODE><B><A HREF="../../java/net/ServerSocket.html#getLocalPort()">getLocalPort</A></B>()</CODE>

<BR>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Returns the port on which this socket is listening.

返回此套接字的监听端口。</TD>

</TR>

<TR BGCOLOR="white" CLASS="TableRowColor">

<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">

<CODE>&nbsp;<A HREF="../../java/net/SocketAddress.html" title="class in java.net">SocketAddress</A></CODE></FONT></TD>

<TD><CODE><B><A HREF="../../java/net/ServerSocket.html#getLocalSocketAddress()">getLocalSocketAddress</A></B>()</CODE>

<BR>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Returns the address of the endpoint this socket is bound to, or

<code>null</code> if it is not bound yet.

返回此套接字绑定的端点地址,如果未绑定,返回null。</TD>

</TR>

<TR BGCOLOR="white" CLASS="TableRowColor">

<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">

<CODE>&nbsp;int</CODE></FONT></TD>

<TD><CODE><B><A HREF="../../java/net/ServerSocket.html#getReceiveBufferSize()">getReceiveBufferSize</A></B>()</CODE>

<BR>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Gets the value of the SO_RCVBUF option for this <tt>ServerSocket</tt>,

that is the proposed buffer size that will be used for Sockets accepted

from this <tt>ServerSocket</tt>.

获得此ServerSocket SO_RCVBUF选项的值,这是用于从此ServerSocket接收的套接字的推荐缓冲区大小。</TD>

</TR>

<TR BGCOLOR="white" CLASS="TableRowColor">

<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">

<CODE>&nbsp;boolean</CODE></FONT></TD>

<TD><CODE><B><A HREF="../../java/net/ServerSocket.html#getReuseAddress()">getReuseAddress</A></B>()</CODE>

<BR>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Tests if SO_REUSEADDR is enabled.

测试是否设置了SO_REUSEADDR选项。</TD>

</TR>

<TR BGCOLOR="white" CLASS="TableRowColor">

<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">

<CODE>&nbsp;int</CODE></FONT></TD>

<TD><CODE><B><A HREF="../../java/net/ServerSocket.html#getSoTimeout()">getSoTimeout</A></B>()</CODE>

<BR>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Retrive setting for SO_TIMEOUT.

获得SO_TIMEOUT选项的设置。</TD>

</TR>

<TR BGCOLOR="white" CLASS="TableRowColor">

<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">

<CODE>protected &nbsp;void</CODE></FONT></TD>

<TD><CODE><B><A HREF="../../java/net/ServerSocket.html#implAccept(java.net.Socket)">implAccept</A></B>(<A HREF="../../java/net/Socket.html" title="class in java.net">Socket</A>&nbsp;s)</CODE>

<BR>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Subclasses of ServerSocket use this method to override accept()

to return their own subclass of socket.

ServerSocket的子类用该方法重载accept()以便返回自己套接字子类。</TD>

</TR>

<TR BGCOLOR="white" CLASS="TableRowColor">

<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">

<CODE>&nbsp;boolean</CODE></FONT></TD>

<TD><CODE><B><A HREF="../../java/net/ServerSocket.html#isBound()">isBound</A></B>()</CODE>

<BR>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Returns the binding state of the ServerSocket.

返回此ServerSocket的绑定状态。</TD>

</TR>

<TR BGCOLOR="white" CLASS="TableRowColor">

<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">

<CODE>&nbsp;boolean</CODE></FONT></TD>

<TD><CODE><B><A HREF="../../java/net/ServerSocket.html#isClosed()">isClosed</A></B>()</CODE>

<BR>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Returns the closed state of the ServerSocket.

返回此ServerSocket的关闭状态。</TD>

</TR>

<TR BGCOLOR="white" CLASS="TableRowColor">

<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">

<CODE>&nbsp;void</CODE></FONT></TD>

<TD><CODE><B><A HREF="../../java/net/ServerSocket.html#setReceiveBufferSize(int)">setReceiveBufferSize</A></B>(int&nbsp;size)</CODE>

<BR>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Sets a default proposed value for the SO_RCVBUF option for sockets

accepted from this <tt>ServerSocket</tt>.

设置从此ServerSocket接收的套接字的SO_RCVBUF选项的默认建议值。</TD>

</TR>

<TR BGCOLOR="white" CLASS="TableRowColor">

<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">

<CODE>&nbsp;void</CODE></FONT></TD>

<TD><CODE><B><A HREF="../../java/net/ServerSocket.html#setReuseAddress(boolean)">setReuseAddress</A></B>(boolean&nbsp;on)</CODE>

<BR>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Enable/disable the SO_REUSEADDR socket option.

设置/取消SO_REUSEADDR套接字选项。</TD>

</TR>

<TR BGCOLOR="white" CLASS="TableRowColor">

<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">

<CODE>static&nbsp;void</CODE></FONT></TD>

<TD><CODE><B><A HREF="../../java/net/ServerSocket.html#setSocketFactory(java.net.SocketImplFactory)">setSocketFactory</A></B>(<A HREF="../../java/net/SocketImplFactory.html" title="interface in java.net">SocketImplFactory</A>&nbsp;fac)</CODE>

<BR>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Sets the server socket implementation factory for the

application.

设置应用程序的服务器套接字实现工厂。</TD>

</TR>

<TR BGCOLOR="white" CLASS="TableRowColor">

<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">

<CODE>&nbsp;void</CODE></FONT></TD>

<TD><CODE><B><A HREF="../../java/net/ServerSocket.html#setSoTimeout(int)">setSoTimeout</A></B>(int&nbsp;timeout)</CODE>

<BR>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Enable/disable SO_TIMEOUT with the specified timeout, in

milliseconds.

用指定的延时(毫秒为单位)设置/取消SO_TIMEOUT选项。</TD>

</TR>

<TR BGCOLOR="white" CLASS="TableRowColor">

<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">

<CODE>&nbsp;<A HREF="../../java/lang/String.html" title="class in java.lang">String</A></CODE></FONT></TD>

<TD><CODE><B><A HREF="../../java/net/ServerSocket.html#toString()">toString</A></B>()</CODE>

<BR>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Returns the implementation address and implementation port of

this socket as a <code>String</code>.

以字符串形式返回此套接字实现的地址与端口。</TD>

</TR>

</TABLE>

&nbsp;<A NAME="methods_inherited_from_class_java.lang.Object"><!-- --></A>

<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">

<TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor">

<TD><B>Methods inherited from class java.lang.<A HREF="../../java/lang/Object.html" title="class in java.lang">Object</A></B></TD>

</TR>

<TR BGCOLOR="white" CLASS="TableRowColor">

<TD><CODE><A HREF="../../java/lang/Object.html#clone()">clone</A>, <A HREF="../../java/lang/Object.html#equals(java.lang.Object)">equals</A>, <A HREF="../../java/lang/Object.html#finalize()">finalize</A>, <A HREF="../../java/lang/Object.html#getClass()">getClass</A>, <A HREF="../../java/lang/Object.html#hashCode()">hashCode</A>, <A HREF="../../java/lang/Object.html#notify()">notify</A>, <A HREF="../../java/lang/Object.html#notifyAll()">notifyAll</A>, <A HREF="../../java/lang/Object.html#wait()">wait</A>, <A HREF="../../java/lang/Object.html#wait(long)">wait</A>, <A HREF="../../java/lang/Object.html#wait(long, int)">wait</A></CODE></TD>

</TR>

</TABLE>

&nbsp;

<P>

<!-- ============ FIELD DETAIL =========== -->

<!-- ========= CONSTRUCTOR DETAIL ======== -->

<A NAME="constructor_detail"><!-- --></A>

<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">

<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">

<TD COLSPAN=1><FONT SIZE="+2">

<B>Constructor Detail</B></FONT></TD>

</TR>

</TABLE>

<A NAME="ServerSocket()"><!-- --></A><H3>

ServerSocket</H3>

<PRE>

public <B>ServerSocket</B>()

throws <A HREF="../../java/io/IOException.html" title="class in java.io">IOException</A></PRE>

<DL>

<DD>Creates an unbound server socket.

创建无绑定服务器套接字。

<P>

<DT><B>Throws:</B>

<DD><CODE><A HREF="../../java/io/IOException.html" title="class in java.io">IOException</A></CODE> - IO error when opening the socket.

当打开套接字时发生I/O错误则抛出。</DL>

<HR>

<A NAME="ServerSocket(int)"><!-- --></A><H3>

ServerSocket</H3>

<PRE>

public <B>ServerSocket</B>(int&nbsp;port)

throws <A HREF="../../java/io/IOException.html" title="class in java.io">IOException</A></PRE>

<DL>

<DD>Creates a server socket, bound to the specified port. A port of

<code>0</code> creates a socket on any free port.

在指定端口创建服务器套接字。端口号为0表示在任意空闲端口创建套接字。

<p>

The maximum queue length for incoming connection indications (a

request to connect) is set to <code>50</code>. If a connection

indication arrives when the queue is full, the connection is refused.

呼入连接指令(连接请求)的最大队列长度为50。如果连接指令到达之时队列已满,连接将被拒绝。

<p>

If the application has specified a server socket factory, that

factory's <code>createSocketImpl</code> method is called to create

the actual socket implementation. Otherwise a "plain" socket is created.

如果应用程序已指定服务器套接字工厂,调用工厂的createSocketImpl方法来创建实际的套接字实现,否则创建一个

“空白”套接字。

<p>

If there is a security manager,

its <code>checkListen</code> method is called

with the <code>port</code> argument

as its argument to ensure the operation is allowed.

This could result in a SecurityException.

如果存在安全管理器,用port作参数调用checkListen方法,以确认操作被允许。这可能导致SecurityException。

<P>

<DT><B>Parameters:</B><DD><CODE>port</CODE> - the port number, or <code>0</code> to use any

free port.

端口号,0表示使用任意空闲端口。

<DT><B>Throws:</B>

<DD><CODE><A HREF="../../java/io/IOException.html" title="class in java.io">IOException</A></CODE> - if an I/O error occurs when opening the socket. 当打开套接字时发生I/O错误则抛出。

<DD><CODE><A HREF="../../java/lang/SecurityException.html" title="class in java.lang">SecurityException</A></CODE> - if a security manager exists and its <code>checkListen</code>

method doesn't allow the operation.

如果SecurityManager存在,它的checkListen方法不允许此操作。<DT><B>See Also:</B><DD><A HREF="../../java/net/SocketImpl.html" title="class in java.net"><CODE>SocketImpl</CODE></A>,

<A HREF="../../java/net/SocketImplFactory.html#createSocketImpl()"><CODE>SocketImplFactory.createSocketImpl()</CODE></A>,

<A HREF="../../java/net/ServerSocket.html#setSocketFactory(java.net.SocketImplFactory)"><CODE>setSocketFactory(java.net.SocketImplFactory)</CODE></A>,

<A HREF="../../java/lang/SecurityManager.html#checkListen(int)"><CODE>SecurityManager.checkListen(int)</CODE></A></DL>

<HR>

<A NAME="ServerSocket(int, int)"><!-- --></A><H3>

ServerSocket</H3>

<PRE>

public <B>ServerSocket</B>(int&nbsp;port,

int&nbsp;backlog)

throws <A HREF="../../java/io/IOException.html" title="class in java.io">IOException</A></PRE>

<DL>

<DD>Creates a server socket and binds it to the specified local port

number, with the specified backlog.

A port number of <code>0</code> creates a socket on any

free port.

创建服务器套接字并绑定在指定端口,使用指定的队列长度。

<p>

The maximum queue length for incoming connection indications (a

request to connect) is set to the <code>backlog</code> parameter. If

a connection indication arrives when the queue is full, the

connection is refused.

呼入连接指令(连接请求)的最大队列长度为backlog参数。如果连接指令到达之时队列已满,连接将被拒绝。

<p>

If the application has specified a server socket factory, that

factory's <code>createSocketImpl</code> method is called to create

the actual socket implementation. Otherwise a "plain" socket is created.

如果应用程序已指定服务器套接字工厂,调用工厂的createSocketImpl方法来创建实际的套接字实现,否则创建一个 “空白”套接字。

<p>

If there is a security manager,

its <code>checkListen</code> method is called

with the <code>port</code> argument

as its argument to ensure the operation is allowed.

This could result in a SecurityException.

如果存在安全管理器,用port作参数调用checkListen方法,以确认操作被允许。这可能导致SecurityException。

<P>The <code>backlog</code> 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.

backlog参数必须是一个大于0的正数。如果传入的值等于或小于0,那么假定为默认值。

<P>

<P>

<DT><B>Parameters:</B><DD><CODE>port</CODE> - the specified port, or <code>0</code> to use

any free port.

指定端口,0表示使用任意空闲端口。<DD><CODE>backlog</CODE> - the maximum length of the queue. 队列的最大长度。

<DT><B>Throws:</B>

<DD><CODE><A HREF="../../java/io/IOException.html" title="class in java.io">IOException</A></CODE> - if an I/O error occurs when opening the socket.

当打开套接字时发生I/O错误则抛出。

<DD><CODE><A HREF="../../java/lang/SecurityException.html" title="class in java.lang">SecurityException</A></CODE> - if a security manager exists and its <code>checkListen</code>

method doesn't allow the operation.

如果SecurityManager存在,它的checkListen方法不允许此操作。<DT><B>See Also:</B><DD><A HREF="../../java/net/SocketImpl.html" title="class in java.net"><CODE>SocketImpl</CODE></A>,

<A HREF="../../java/net/SocketImplFactory.html#createSocketImpl()"><CODE>SocketImplFactory.createSocketImpl()</CODE></A>,

<A HREF="../../java/net/ServerSocket.html#setSocketFactory(java.net.SocketImplFactory)"><CODE>setSocketFactory(java.net.SocketImplFactory)</CODE></A>,

<A HREF="../../java/lang/SecurityManager.html#checkListen(int)"><CODE>SecurityManager.checkListen(int)</CODE></A></DL>

<HR>

<A NAME="ServerSocket(int, int, java.net.InetAddress)"><!-- --></A><H3>

ServerSocket</H3>

<PRE>

public <B>ServerSocket</B>(int&nbsp;port,

int&nbsp;backlog,

<A HREF="../../java/net/InetAddress.html" title="class in java.net">InetAddress</A>&nbsp;bindAddr)

throws <A HREF="../../java/io/IOException.html" title="class in java.io">IOException</A></PRE>

<DL>

<DD>Create a server with the specified port, listen backlog, and

local IP address to bind to. The <i>bindAddr</i> argument

can be used on a multi-homed host for a ServerSocket that

will only accept connect requests to one of its addresses.

If <i>bindAddr</i> is null, it will default accepting

connections on any/all local addresses.

The port must be between 0 and 65535, inclusive.

使用指定端口、监听队列和绑定地址创建服务器。

<P>If there is a security manager, this method

calls its <code>checkListen</code> method

with the <code>port</code> argument

as its argument to ensure the operation is allowed.

This could result in a SecurityException.

如果存在安全管理器,用port作参数调用checkListen方法,以确认操作被允许。这可能导致SecurityException。

<P>The <code>backlog</code> 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.

backlog参数必须是一个大于0的正数。如果传入的值等于或小于0,那么假定为默认值。

<P>

<P>

<DT><B>Parameters:</B><DD><CODE>port</CODE> - the local TCP port<DD><CODE>backlog</CODE> - the listen backlog 监听队列<DD><CODE>bindAddr</CODE> - the local InetAddress the server will bind to 服务器要绑定的本地InetAddress

<DT><B>Throws:</B>

<DD><CODE><A HREF="../../java/lang/SecurityException.html" title="class in java.lang">SecurityException</A></CODE> - if a security manager exists and

its <code>checkListen</code> method doesn't allow the operation.

如果SecurityManager存在,它的checkListen方法不允许此操作。

<DD><CODE><A HREF="../../java/io/IOException.html" title="class in java.io">IOException</A></CODE> - if an I/O error occurs when opening the socket.

当打开套接字时发生I/O错误则抛出。<DT><B>Since:</B></DT>

<DD>JDK1.1</DD>

<DT><B>See Also:</B><DD><A HREF="../../java/net/SocketOptions.html" title="interface in java.net"><CODE>SocketOptions</CODE></A>,

<A HREF="../../java/net/SocketImpl.html" title="class in java.net"><CODE>SocketImpl</CODE></A>,

<A HREF="../../java/lang/SecurityManager.html#checkListen(int)"><CODE>SecurityManager.checkListen(int)</CODE></A></DL>

<!-- ============ METHOD DETAIL ========== -->

<A NAME="method_detail"><!-- --></A>

<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">

<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">

<TD COLSPAN=1><FONT SIZE="+2">

<B>Method Detail</B></FONT></TD>

</TR>

</TABLE>

<A NAME="bind(java.net.SocketAddress)"><!-- --></A><H3>

bind</H3>

<PRE>

public void <B>bind</B>(<A HREF="../../java/net/SocketAddress.html" title="class in java.net">SocketAddress</A>&nbsp;endpoint)

throws <A HREF="../../java/io/IOException.html" title="class in java.io">IOException</A></PRE>

<DL>

<DD>Binds the <code>ServerSocket</code> to a specific address

(IP address and port number).

将ServerSocket绑定到指定地址(IP地址和端口号)。

<p>

If the address is <code>null</code>, then the system will pick up

an ephemeral port and a valid local address to bind the socket.

如果地址为null,那么系统将选择一个临时端口和一个有效本地地址来绑定套接字。

<p>

<P>

<DD><DL>

<DT><B>Parameters:</B><DD><CODE>endpoint</CODE> - The IP address & port number to bind to. 要绑定的IP地址和端口号。

<DT><B>Throws:</B>

<DD><CODE><A HREF="../../java/io/IOException.html" title="class in java.io">IOException</A></CODE> - if the bind operation fails, or if the socket

is already bound.

如果绑定操作失败,或者套接字已被绑定时抛出。

<DD><CODE><A HREF="../../java/lang/SecurityException.html" title="class in java.lang">SecurityException</A></CODE> - if a <code>SecurityManager</code> is present and

its <code>checkListen</code> method doesn't allow the operation.

如果SecurityManager存在,它的checkListen方法不允许此操作。

<DD><CODE><A HREF="../../java/lang/IllegalArgumentException.html" title="class in java.lang">IllegalArgumentException</A></CODE> - if endpoint is a

SocketAddress subclass not supported by this socket

如果端点是一个不被此套接字支持的SocketAddress子类时抛出

<DT><B>Since:</B></DT>

<DD>1.4</DD>

</DL>

</DD>

</DL>

<HR>

<A NAME="bind(java.net.SocketAddress, int)"><!-- --></A><H3>

bind</H3>

<PRE>

public void <B>bind</B>(<A HREF="../../java/net/SocketAddress.html" title="class in java.net">SocketAddress</A>&nbsp;endpoint,

int&nbsp;backlog)

throws <A HREF="../../java/io/IOException.html" title="class in java.io">IOException</A></PRE>

<DL>

<DD>Binds the <code>ServerSocket</code> to a specific address

(IP address and port number).

将ServerSocket绑定到指定地址(IP地址和端口号)。

<p>

If the address is <code>null</code>, then the system will pick up

an ephemeral port and a valid local address to bind the socket.

如果地址为null,那么系统将选择一个临时端口和一个有效本地地址来绑定套接字。

<P>

The <code>backlog</code> 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.

backlog参数必须是一个大于0的正数。如果传入的值小于等于0,则使用默认值。

<P>

<DD><DL>

<DT><B>Parameters:</B><DD><CODE>endpoint</CODE> - The IP address & port number to bind to. 要绑定的IP地址和端口号。<DD><CODE>backlog</CODE> - The listen backlog length. 监听队列长度。

<DT><B>Throws:</B>

<DD><CODE><A HREF="../../java/io/IOException.html" title="class in java.io">IOException</A></CODE> - if the bind operation fails, or if the socket

is already bound. 如果绑定操作失败,或者套接字已被绑定时抛出。

<DD><CODE><A HREF="../../java/lang/SecurityException.html" title="class in java.lang">SecurityException</A></CODE> - if a <code>SecurityManager</code> is present and

its <code>checkListen</code> method doesn't allow the operation. 如果SecurityManager存在,它的checkListen方法不允许此操作。

<DD><CODE><A HREF="../../java/lang/IllegalArgumentException.html" title="class in java.lang">IllegalArgumentException</A></CODE> - if endpoint is a

SocketAddress subclass not supported by this socket

如果端点是一个不被此套接字支持的SocketAddress子类时抛出<DT><B>Since:</B></DT>

<DD>1.4</DD>

</DL>

</DD>

</DL>

<HR>

<A NAME="getInetAddress()"><!-- --></A><H3>

getInetAddress</H3>

<PRE>

public <A HREF="../../java/net/InetAddress.html" title="class in java.net">InetAddress</A> <B>getInetAddress</B>()</PRE>

<DL>

<DD>Returns the local address of this server socket.

返回此服务器套接字的本地地址。

<P>

<DD><DL>

<DT><B>Returns:</B><DD>the address to which this socket is bound,

or <code>null</code> if the socket is unbound.

此套接字绑定的地址,如果未绑定,返回null。</DL>

</DD>

</DL>

<HR>

<A NAME="getLocalPort()"><!-- --></A><H3>

getLocalPort</H3>

<PRE>

public int <B>getLocalPort</B>()</PRE>

<DL>

<DD>Returns the port on which this socket is listening.

返回此套接字的监听端口。

<P>

<DD><DL>

<DT><B>Returns:</B><DD>the port number to which this socket is listening or

-1 if the socket is not bound yet.

此套接字监听的端口号,如果套接字未绑定,返回-1。</DL>

</DD>

</DL>

<HR>

<A NAME="getLocalSocketAddress()"><!-- --></A><H3>

getLocalSocketAddress</H3>

<PRE>

public <A HREF="../../java/net/SocketAddress.html" title="class in java.net">SocketAddress</A> <B>getLocalSocketAddress</B>()</PRE>

<DL>

<DD>Returns the address of the endpoint this socket is bound to, or

<code>null</code> if it is not bound yet.

返回此套接字绑定的端点地址,如果未绑定,返回null。

<P>

<DD><DL>

<DT><B>Returns:</B><DD>a <code>SocketAddress</code> representing the local endpoint of this

socket, or <code>null</code> if it is not bound yet.

表示此套接字本地端点的SocketAddress,如果未绑定,返回null。<DT><B>Since:</B></DT>

<DD>1.4</DD>

<DT><B>See Also:</B><DD><A HREF="../../java/net/ServerSocket.html#getInetAddress()"><CODE>getInetAddress()</CODE></A>,

<A HREF="../../java/net/ServerSocket.html#getLocalPort()"><CODE>getLocalPort()</CODE></A>,

<A HREF="../../java/net/ServerSocket.html#bind(java.net.SocketAddress)"><CODE>bind(SocketAddress)</CODE></A></DL>

</DD>

</DL>

<HR>

<A NAME="accept()"><!-- --></A><H3>

accept</H3>

<PRE>

public <A HREF="../../java/net/Socket.html" title="class in java.net">Socket</A> <B>accept</B>()

throws <A HREF="../../java/io/IOException.html" title="class in java.io">IOException</A></PRE>

<DL>

<DD>Listens for a connection to be made to this socket and accepts

it. The method blocks until a connection is made.

监听发起到此套接字的连接并接受它。

<p>A new Socket <code>s</code> is created and, if there

is a security manager,

the security manager's <code>checkAccept</code> method is called

with <code>s.getInetAddress().getHostAddress()</code> and

<code>s.getPort()</code>

as its arguments to ensure the operation is allowed.

This could result in a SecurityException.

创建一个新的Socket s,如果存在安全管理器,用s.getInetAddress().getHostAddress()和s.getPort()的返回值作为

参数调用安全管理器的checkAccept方法,以确认操作允许。这可能导致SecurityException。

<P>

<DD><DL>

<DT><B>Returns:</B><DD>the new Socket 新的Socket

<DT><B>Throws:</B>

<DD><CODE><A HREF="../../java/io/IOException.html" title="class in java.io">IOException</A></CODE> - if an I/O error occurs when waiting for a

connection. 等待连接时发生I/O错误则抛出。

<DD><CODE><A HREF="../../java/lang/SecurityException.html" title="class in java.lang">SecurityException</A></CODE> - if a security manager exists and its

<code>checkListen</code> method doesn't allow the operation. 如果安全管理器存在,它的checkListen方法不允许该操作时抛出。

<DD><CODE><A HREF="../../java/net/SocketTimeoutException.html" title="class in java.net">SocketTimeoutException</A></CODE> - if a timeout was previously set with setSoTimeout and

the timeout has been reached.

之前用setSoTimeout设置了延时,而延时已满时抛出。

<DD><CODE><A HREF="../../java/nio/channels/IllegalBlockingModeException.html" title="class in java.nio.channels">IllegalBlockingModeException</A></CODE> - if this socket has an associated channel,

and the channel is in non-blocking mode.

如果此套接字有对应的通道且通道处于非阻塞模式时抛出。<DT><B>See Also:</B><DD><A HREF="../../java/lang/SecurityManager.html#checkAccept(java.lang.String, int)"><CODE>SecurityManager.checkAccept(java.lang.String, int)</CODE></A></DL>

</DD>

</DL>

<HR>

<A NAME="implAccept(java.net.Socket)"><!-- --></A><H3>

implAccept</H3>

<PRE>

protected final void <B>implAccept</B>(<A HREF="../../java/net/Socket.html" title="class in java.net">Socket</A>&nbsp;s)

throws <A HREF="../../java/io/IOException.html" title="class in java.io">IOException</A></PRE>

<DL>

<DD>Subclasses of ServerSocket use this method to override accept()

to return their own subclass of socket. So a FooServerSocket

will typically hand this method an <i>empty</i> FooSocket. On

return from implAccept the FooSocket will be connected to a client.

ServerSocket的子类用该方法重载accept()以便返回自己套接字子类。

<P>

<DD><DL>

<DT><B>Parameters:</B><DD><CODE>s</CODE> - the Socket 套接字

<DT><B>Throws:</B>

<DD><CODE><A HREF="../../java/nio/channels/IllegalBlockingModeException.html" title="class in java.nio.channels">IllegalBlockingModeException</A></CODE> - if this socket has an associated channel,

and the channel is in non-blocking mode 如果此套接字有对应的通道且通道处于非阻塞模式时抛出。

<DD><CODE><A HREF="../../java/io/IOException.html" title="class in java.io">IOException</A></CODE> - if an I/O error occurs when waiting

for a connection.

等待连接时发生I/O错误则抛出。<DT><B>Since:</B></DT>

<DD>JDK1.1</DD>

</DL>

</DD>

</DL>

<HR>

<A NAME="close()"><!-- --></A><H3>

close</H3>

<PRE>

public void <B>close</B>()

throws <A HREF="../../java/io/IOException.html" title="class in java.io">IOException</A></PRE>

<DL>

<DD>Closes this socket.

Any thread currently blocked in <A HREF="../../java/net/ServerSocket.html#accept()"><CODE>accept()</CODE></A> will throw

a <A HREF="../../java/net/SocketException.html" title="class in java.net"><CODE>SocketException</CODE></A>.

关闭套接字。任何目前阻塞于accept()的线程都将抛出SocketException。

<p> If this socket has an associated channel then the channel is closed

as well.

如果此套接字有对应通道,那么同时关闭通道。

<P>

<DD><DL>

<DT><B>Throws:</B>

<DD><CODE><A HREF="../../java/io/IOException.html" title="class in java.io">IOException</A></CODE> - if an I/O error occurs when closing the socket. 如果关闭套接字时有I/O错误则抛出。</DL>

</DD>

</DL>

<HR>

<A NAME="getChannel()"><!-- --></A><H3>

getChannel</H3>

<PRE>

public <A HREF="../../java/nio/channels/ServerSocketChannel.html" title="class in java.nio.channels">ServerSocketChannel</A> <B>getChannel</B>()</PRE>

<DL>

<DD>Returns the unique <A HREF="../../java/nio/channels/ServerSocketChannel.html" title="class in java.nio.channels"><CODE>ServerSocketChannel</CODE></A> object

associated with this socket, if any.

如果有,返回同此套接字唯一关联的ServerSocketChannel对象。

<p> A server socket will have a channel if, and only if, the channel

itself was created via the <A HREF="../../java/nio/channels/ServerSocketChannel.html#open()"><CODE>ServerSocketChannel.open</CODE></A>

method.

只有自身通过ServerSocketChannel.open创建通道,服务器套接字才有通道。

<P>

<DD><DL>

<DT><B>Returns:</B><DD>the server-socket channel associated with this socket,

or <tt>null</tt> if this socket was not created

for a channel

此套接字的对应的服务器套接字通道,如果套接字未创建通道,返回null<DT><B>Since:</B></DT>

<DD>1.4</DD>

</DL>

</DD>

</DL>

<HR>

<A NAME="isBound()"><!-- --></A><H3>

isBound</H3>

<PRE>

public boolean <B>isBound</B>()</PRE>

<DL>

<DD>Returns the binding state of the ServerSocket.

返回此ServerSocket的绑定状态。

<P>

<DD><DL>

<DT><B>Returns:</B><DD>true if the ServerSocket succesfuly bound to an address

如果ServerSocket被成功绑定到某地址,返回true<DT><B>Since:</B></DT>

<DD>1.4</DD>

</DL>

</DD>

</DL>

<HR>

<A NAME="isClosed()"><!-- --></A><H3>

isClosed</H3>

<PRE>

public boolean <B>isClosed</B>()</PRE>

<DL>

<DD>Returns the closed state of the ServerSocket.

返回此ServerSocket的关闭状态。

<P>

<DD><DL>

<DT><B>Returns:</B><DD>true if the socket has been closed 如果此套接字被关闭,返回true<DT><B>Since:</B></DT>

<DD>1.4</DD>

</DL>

</DD>

</DL>

<HR>

<A NAME="setSoTimeout(int)"><!-- --></A><H3>

setSoTimeout</H3>

<PRE>

public void <B>setSoTimeout</B>(int&nbsp;timeout)

throws <A HREF="../../java/net/SocketException.html" title="class in java.net">SocketException</A></PRE>

<DL>

<DD>Enable/disable SO_TIMEOUT with the specified timeout, in

milliseconds. With this option set to a non-zero timeout,

a call to accept() for this ServerSocket

will block for only this amount of time. If the timeout expires,

a <B>java.net.SocketTimeoutException</B> is raised, though the

ServerSocket is still valid. The option <B>must</B> be enabled

prior to entering the blocking operation to have effect. The

timeout must be > 0.

A timeout of zero is interpreted as an infinite timeout.

用指定的延时(毫秒为单位)设置/取消SO_TIMEOUT选项。用设置的非零延时选项,调用此ServerSocket的accept()

将阻塞定量的时间。如果延时期满,将引起java.net.SocketTimeoutException,虽然ServerSocket仍然无效。选项

必须在进入阻塞操作前设置才有效。延时值必须>0。0值被解释为无限延时。

<P>

<DD><DL>

<DT><B>Parameters:</B><DD><CODE>timeout</CODE> - the specified timeout, in milliseconds 指定的延时,以毫秒为单位

<DT><B>Throws:</B>

<DD><CODE><A HREF="../../java/net/SocketException.html" title="class in java.net">SocketException</A></CODE> - if there is an error in

the underlying protocol, such as a TCP error.

如果底层协议存在错误,例如TCP错误时抛出。<DT><B>Since:</B></DT>

<DD>JDK1.1</DD>

<DT><B>See Also:</B><DD><A HREF="../../java/net/ServerSocket.html#getSoTimeout()"><CODE>getSoTimeout()</CODE></A></DL>

</DD>

</DL>

<HR>

<A NAME="getSoTimeout()"><!-- --></A><H3>

getSoTimeout</H3>

<PRE>

public int <B>getSoTimeout</B>()

throws <A HREF="../../java/io/IOException.html" title="class in java.io">IOException</A></PRE>

<DL>

<DD>Retrive setting for SO_TIMEOUT. 0 returns implies that the

option is disabled (i.e., timeout of infinity).

获得SO_TIMEOUT选项的设置。返回0意味着不设置此选项(即超时无限制)。

<P>

<DD><DL>

<DT><B>Returns:</B><DD>the SO_TIMEOUT value SO_TIMEOUT值

<DT><B>Throws:</B>

<DD><CODE><A HREF="../../java/io/IOException.html" title="class in java.io">IOException</A></CODE> - if an I/O error occurs 如果发生I/O错误则抛出<DT><B>Since:</B></DT>

<DD>JDK1.1</DD>

<DT><B>See Also:</B><DD><A HREF="../../java/net/ServerSocket.html#setSoTimeout(int)"><CODE>setSoTimeout(int)</CODE></A></DL>

</DD>

</DL>

<HR>

<A NAME="setReuseAddress(boolean)"><!-- --></A><H3>

setReuseAddress</H3>

<PRE>

public void <B>setReuseAddress</B>(boolean&nbsp;on)

throws <A HREF="../../java/net/SocketException.html" title="class in java.net">SocketException</A></PRE>

<DL>

<DD>Enable/disable the SO_REUSEADDR socket option.

设置/取消SO_REUSEADDR套接字选项。

<p>

When a TCP connection is closed the connection may remain

in a timeout state for a period of time after the connection

is closed (typically known as the <tt>TIME_WAIT</tt> state

or <tt>2MSL</tt> wait state).

For applications using a well known socket address or port

it may not be possible to bind a socket to the required

<tt>SocketAddress</tt> if there is a connection in the

timeout state involving the socket address or port.

对于使用众所周知的套接字地址和端口的应用程序,当关闭TCP连接时,会在连接关闭后保持一段延时状态(通常作为TIME_WAIT状态或2MSL等待状态)。

如果涉及的套接字地址和端口处于延时状态。

<p>

Enabling <tt>SO_REUSEADDR</tt> prior to binding the socket

using <A HREF="../../java/net/ServerSocket.html#bind(java.net.SocketAddress)"><CODE>bind(SocketAddress)</CODE></A> allows the socket to be

bound even though a previous connection is in a timeout

state.

在使用bind(SocketAddress)绑定套接字前设置SO_REUSEADDR选项使得套接字能够绑定,尽管先前的连接处于延时状态。

<p>

When a <tt>ServerSocket</tt> is created the initial setting

of <tt>SO_REUSEADDR</tt> is not defined. Applications can

use <A HREF="../../java/net/ServerSocket.html#getReuseAddress()"><CODE>getReuseAddress()</CODE></A> to determine the initial

setting of <tt>SO_REUSEADDR</tt>.

创建ServerSocket时,SO_REUSEADDR的初始设置未定义。应用程序可以使用getReuseAddress()确定SO_REUSEADDR的初始设置。

<p>

The behaviour when <tt>SO_REUSEADDR</tt> is enabled or

disabled after a socket is bound (See <A HREF="../../java/net/ServerSocket.html#isBound()"><CODE>isBound()</CODE></A>)

is not defined.

在套接字绑定后设置或取消SO_REUSEADDR的行为未定义。

<P>

<DD><DL>

<DT><B>Parameters:</B><DD><CODE>on</CODE> - whether to enable or disable the socket option 是否设置该套接字选项

<DT><B>Throws:</B>

<DD><CODE><A HREF="../../java/net/SocketException.html" title="class in java.net">SocketException</A></CODE> - if an error occurs enabling or

disabling the <tt>SO_RESUEADDR</tt> socket option,

or the socket is closed.

在设置或取消SO_RESUEADDR套接字选项时出现错误或套接字被关闭时抛出。<DT><B>Since:</B></DT>

<DD>1.4</DD>

<DT><B>See Also:</B><DD><A HREF="../../java/net/ServerSocket.html#getReuseAddress()"><CODE>getReuseAddress()</CODE></A>,

<A HREF="../../java/net/ServerSocket.html#bind(java.net.SocketAddress)"><CODE>bind(SocketAddress)</CODE></A>,

<A HREF="../../java/net/ServerSocket.html#isBound()"><CODE>isBound()</CODE></A>,

<A HREF="../../java/net/ServerSocket.html#isClosed()"><CODE>isClosed()</CODE></A></DL>

</DD>

</DL>

<HR>

<A NAME="getReuseAddress()"><!-- --></A><H3>

getReuseAddress</H3>

<PRE>

public boolean <B>getReuseAddress</B>()

throws <A HREF="../../java/net/SocketException.html" title="class in java.net">SocketException</A></PRE>

<DL>

<DD>Tests if SO_REUSEADDR is enabled.

测试是否设置了SO_REUSEADDR选项。

<P>

<DD><DL>

<DT><B>Returns:</B><DD>a <code>boolean</code> indicating whether or not SO_REUSEADDR is enabled.

表示是否设置了SO_REUSEADDR选项的布尔值。

<DT><B>Throws:</B>

<DD><CODE><A HREF="../../java/net/SocketException.html" title="class in java.net">SocketException</A></CODE> - if there is an error

in the underlying protocol, such as a TCP error.

如果底层协议存在错误,例如TCP错误时抛出。<DT><B>Since:</B></DT>

<DD>1.4</DD>

<DT><B>See Also:</B><DD><A HREF="../../java/net/ServerSocket.html#setReuseAddress(boolean)"><CODE>setReuseAddress(boolean)</CODE></A></DL>

</DD>

</DL>

<HR>

<A NAME="toString()"><!-- --></A><H3>

toString</H3>

<PRE>

public <A HREF="../../java/lang/String.html" title="class in java.lang">String</A> <B>toString</B>()</PRE>

<DL>

<DD>Returns the implementation address and implementation port of

this socket as a <code>String</code>.

以字符串形式返回此套接字实现的地址与端口。

<P>

<DD><DL>

<DT><B>Overrides:</B><DD><CODE><A HREF="../../java/lang/Object.html#toString()">toString</A></CODE> in class <CODE><A HREF="../../java/lang/Object.html" title="class in java.lang">Object</A></CODE></DL>

</DD>

<DD><DL>

<DT><B>Returns:</B><DD>a string representation of this socket. 此套接字的字符串形式。</DL>

</DD>

</DL>

<HR>

<A NAME="setSocketFactory(java.net.SocketImplFactory)"><!-- --></A><H3>

setSocketFactory</H3>

<PRE>

public static void <B>setSocketFactory</B>(<A HREF="../../java/net/SocketImplFactory.html" title="interface in java.net">SocketImplFactory</A>&nbsp;fac)

throws <A HREF="../../java/io/IOException.html" title="class in java.io">IOException</A></PRE>

<DL>

<DD>Sets the server socket implementation factory for the

application. The factory can be specified only once.

设置应用程序的服务器套接字实现工厂。工厂只能被指定一次。

<p>

When an application creates a new server socket, the socket

implementation factory's <code>createSocketImpl</code> method is

called to create the actual socket implementation.

当应用程序创建一个新的服务器套接字时,调用套接字实现工厂的createSocketImpl方法创建一个实际的套接字实现。

<p>

If there is a security manager, this method first calls

the security manager's <code>checkSetFactory</code> method

to ensure the operation is allowed.

This could result in a SecurityException.

如果存在安全管理器,该方法首先调用安全管理器的checkSetFactory方法以确认操作允许,这可能造成SecurityException。

<P>

<DD><DL>

<DT><B>Parameters:</B><DD><CODE>fac</CODE> - the desired factory. 期望工厂。

<DT><B>Throws:</B>

<DD><CODE><A HREF="../../java/io/IOException.html" title="class in java.io">IOException</A></CODE> - if an I/O error occurs when setting the

socket factory. 当设置套接字工厂时发生I/O错误则抛出。

<DD><CODE><A HREF="../../java/net/SocketException.html" title="class in java.net">SocketException</A></CODE> - if the factory has already been defined. 如果该工厂已经被定义时抛出。

<DD><CODE><A HREF="../../java/lang/SecurityException.html" title="class in java.lang">SecurityException</A></CODE> - if a security manager exists and its

<code>checkSetFactory</code> method doesn't allow the operation.

如果安全管理器存在,它的checkSetFactory方法不允许该操作时抛出。<DT><B>See Also:</B><DD><A HREF="../../java/net/SocketImplFactory.html#createSocketImpl()"><CODE>SocketImplFactory.createSocketImpl()</CODE></A>,

<A HREF="../../java/lang/SecurityManager.html#checkSetFactory()"><CODE>SecurityManager.checkSetFactory()</CODE></A></DL>

</DD>

</DL>

<HR>

<A NAME="setReceiveBufferSize(int)"><!-- --></A><H3>

setReceiveBufferSize</H3>

<PRE>

public void <B>setReceiveBufferSize</B>(int&nbsp;size)

throws <A HREF="../../java/net/SocketException.html" title="class in java.net">SocketException</A></PRE>

<DL>

<DD>Sets a default proposed value for the SO_RCVBUF option for sockets

accepted from this <tt>ServerSocket</tt>. The value actually set

in the accepted socket must be determined by calling

<A HREF="../../java/net/Socket.html#getReceiveBufferSize()"><CODE>Socket.getReceiveBufferSize()</CODE></A> after the socket

is returned by <A HREF="../../java/net/ServerSocket.html#accept()"><CODE>accept()</CODE></A>.

设置从此ServerSocket接收的套接字的SO_RCVBUF选项的默认建议值。由accept()返回套接字后,其中设置的值必须通过调用

Socket.getReceiveBufferSize()来确定。

<p>

The value of SO_RCVBUF is used both to set the size of the internal

socket receive buffer, and to set the size of the TCP receive window

that is advertized to the remote peer.

SO_RCVBUF的值用来设置内部套接字接收缓冲区和通知给远端对方的TCP接收窗口的大小。

<p>

It is possible to change the value subsequently, by calling

<A HREF="../../java/net/Socket.html#setReceiveBufferSize(int)"><CODE>Socket.setReceiveBufferSize(int)</CODE></A>. However, if the application

wishes to allow a receive window larger than 64K bytes, as defined by RFC1323

then the proposed value must be set in the ServerSocket <B>before</B>

it is bound to a local address. This implies, that the ServerSocket must be

created with the no-argument constructor, then setReceiveBufferSize() must

be called and lastly the ServerSocket is bound to an address by calling bind().

通过调用Socket.setReceiveBufferSize(int)可以改变这个值。然而如果应用程序希望接收窗口大于64KB,

则ServerSocket必须在被绑定到本地地址前设置建议值。这意味着,服务器套接字必须用无参数构造函数创建,然后必须

调用setReceiveBufferSize(),最后调用bind()将ServerSocket绑定到地址。

<p>

Failure to do this will not cause an error, and the buffer size may be set to the

requested value but the TCP receive window in sockets accepted from

this ServerSocket will be no larger than 64K bytes.

操作失败将导致错误,且缓冲区大小可能被设置为请求值,但此ServerSocket产生的接收套接字的TCP接收窗口

将不再大于64KB。

<P>

<DD><DL>

<DT><B>Parameters:</B><DD><CODE>size</CODE> - the size to which to set the receive buffer

size. This value must be greater than 0.

设置的接收缓冲区大小值,必须>0。

<DT><B>Throws:</B>

<DD><CODE><A HREF="../../java/net/SocketException.html" title="class in java.net">SocketException</A></CODE> - if there is an error

in the underlying protocol, such as a TCP error.

如果底层协议存在错误,例如TCP错误时抛出。

<DD><CODE><A HREF="../../java/lang/IllegalArgumentException.html" title="class in java.lang">IllegalArgumentException</A></CODE> - if the

value is 0 or is negative.

如果该值为0,或为负数时抛出。<DT><B>Since:</B></DT>

<DD>1.4</DD>

<DT><B>See Also:</B><DD><A HREF="../../java/net/ServerSocket.html#getReceiveBufferSize()"><CODE>getReceiveBufferSize()</CODE></A></DL>

</DD>

</DL>

<HR>

<A NAME="getReceiveBufferSize()"><!-- --></A><H3>

getReceiveBufferSize</H3>

<PRE>

public int <B>getReceiveBufferSize</B>()

throws <A HREF="../../java/net/SocketException.html" title="class in java.net">SocketException</A></PRE>

<DL>

<DD>Gets the value of the SO_RCVBUF option for this <tt>ServerSocket</tt>,

that is the proposed buffer size that will be used for Sockets accepted

from this <tt>ServerSocket</tt>.

获得此ServerSocket SO_RCVBUF选项的值,这是用于从此ServerSocket接收的套接字的推荐缓冲区大小。

<p>Note, the value actually set in the accepted socket is determined by

calling <A HREF="../../java/net/Socket.html#getReceiveBufferSize()"><CODE>Socket.getReceiveBufferSize()</CODE></A>.

注意,在接收套接字中该值的设置实际上通过调用Socket.getReceiveBufferSize()来确定。

<P>

<DD><DL>

<DT><B>Returns:</B><DD>the value of the SO_RCVBUF option for this <tt>Socket</tt>. 此Socket的SO_RCVBUF选项值。

<DT><B>Throws:</B>

<DD><CODE><A HREF="../../java/net/SocketException.html" title="class in java.net">SocketException</A></CODE> - if there is an error

in the underlying protocol, such as a TCP error.如果底层协议存在错误,例如TCP错误时抛出。<DT><B>Since:</B></DT>

<DD>1.4</DD>

<DT><B>See Also:</B><DD><A HREF="../../java/net/ServerSocket.html#setReceiveBufferSize(int)"><CODE>setReceiveBufferSize(int)</CODE></A></DL>

</DD>

</DL>

<!-- ========= END OF CLASS DATA ========= -->

<HR>

<!-- ======= START OF BOTTOM NAVBAR ====== -->

<A NAME="navbar_bottom"><!-- --></A>

<A HREF="#skip-navbar_bottom" title="Skip navigation links"></A>

<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY="">

<TR>

<TD COLSPAN=3 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">

<A NAME="navbar_bottom_firstrow"><!-- --></A>

<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY="">

<TR ALIGN="center" VALIGN="top">

<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A>&nbsp;</TD>

<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A>&nbsp;</TD>

<TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT>&nbsp;</TD>

<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="class-use/ServerSocket.html"><FONT CLASS="NavBarFont1"><B>Use</B></FONT></A>&nbsp;</TD>

<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>

<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>

<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../index-files/index-1.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>

<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>

</TR>

</TABLE>

</TD>

<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>

<b>Java<sup><font size=-2>TM</font></sup>&nbsp;2&nbsp;Platform<br>Std.&nbsp;Ed. v1.4.2</b></EM>

</TD>

</TR>

<TR>

<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">

&nbsp;<A HREF="../../java/net/PasswordAuthentication.html" title="class in java.net"><B>PREV CLASS</B></A>&nbsp;

&nbsp;<A HREF="../../java/net/Socket.html" title="class in java.net"><B>NEXT CLASS</B></A></FONT></TD>

<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">

<A HREF="../../index.html" target="_top"><B>FRAMES</B></A> &nbsp;

&nbsp;<A HREF="ServerSocket.html" target="_top"><B>NO FRAMES</B></A> &nbsp;

&nbsp;<SCRIPT type="text/javascript">

<!--

if(window==top) {

document.writeln('<A HREF="../../allclasses-noframe.html"><B>All Classes</B></A>');

}

//-->

</SCRIPT>

<NOSCRIPT>

<A HREF="../../allclasses-noframe.html"><B>All Classes</B></A>

</NOSCRIPT>

</FONT></TD>

</TR>

<TR>

<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">

SUMMARY:&nbsp;NESTED&nbsp;|&nbsp;FIELD&nbsp;|&nbsp;<A HREF="#constructor_summary">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_summary">METHOD</A></FONT></TD>

<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">

DETAIL:&nbsp;FIELD&nbsp;|&nbsp;<A HREF="#constructor_detail">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_detail">METHOD</A></FONT></TD>

</TR>

</TABLE>

<A NAME="skip-navbar_bottom"></A>

<!-- ======== END OF BOTTOM NAVBAR ======= -->

<HR>

<font size="-1"><a href="http://java.sun.com/cgi-bin/bugreport.cgi">Submit a bug or feature</a><br>For further API reference and developer documentation, see <a href="../../../relnotes/devdocs-vs-specs.html">Java 2 SDK SE Developer Documentation</a>. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples. <p>Copyright 2003 Sun Microsystems, Inc. All rights reserved. Use is subject to <a href="../../../relnotes/license.html">license terms</a>. Also see the <a href="http://java.sun.com/docs/redist.html">documentation redistribution policy</a>.</font>

</BODY>

</HTML>

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有