⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 datagramsocket.html

📁 API資料大全
💻 HTML
📖 第 1 页 / 共 3 页
字号:
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Sets the datagram 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/DatagramSocket.html#setReceiveBufferSize(int)">setReceiveBufferSize</A></B>(int&nbsp;size)</CODE><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Sets the SO_RCVBUF option to the specified value for this <tt>DatagramSocket</tt>.</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/DatagramSocket.html#setSendBufferSize(int)">setSendBufferSize</A></B>(int&nbsp;size)</CODE><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Sets the SO_SNDBUF option to the specified value for this <tt>DatagramSocket</tt>.</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/DatagramSocket.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.</TD></TR></TABLE>&nbsp;<A NAME="methods_inherited_from_class_java.lang.Object"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"><TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor"><TD><B>Methods inherited from class java.lang.<A HREF="../../java/lang/Object.html">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#toString()">toString</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" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"><TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"><TD COLSPAN=1><FONT SIZE="+2"><B>Constructor Detail</B></FONT></TD></TR></TABLE><A NAME="DatagramSocket()"><!-- --></A><H3>DatagramSocket</H3><PRE>public <B>DatagramSocket</B>()               throws <A HREF="../../java/net/SocketException.html">SocketException</A></PRE><DL><DD>Constructs a datagram socket and binds it to any available port on the local host machine.  <p>If there is a security manager,  its <code>checkListen</code> method is first called with 0 as its argument to ensure the operation is allowed.  This could result in a SecurityException.<DD><DL><DT><B>Throws:</B><DD><CODE><A HREF="../../java/net/SocketException.html">SocketException</A></CODE> - if the socket could not be opened,               or the socket could not bind to the specified local port.<DD><CODE><A HREF="../../java/lang/SecurityException.html">SecurityException</A></CODE> - if a security manager exists and its               <code>checkListen</code> method doesn't allow the operation.<DT><B>See Also: </B><DD><A HREF="../../java/lang/SecurityManager.html#checkListen(int)"><CODE>SecurityManager.checkListen(int)</CODE></A></DL></DD></DL><HR><A NAME="DatagramSocket(int)"><!-- --></A><H3>DatagramSocket</H3><PRE>public <B>DatagramSocket</B>(int&nbsp;port)               throws <A HREF="../../java/net/SocketException.html">SocketException</A></PRE><DL><DD>Constructs a datagram socket and binds it to the specified port on the local host machine.  <p>If there is a security manager,  its <code>checkListen</code> method is first called with the <code>port</code> argument as its argument to ensure the operation is allowed.  This could result in a SecurityException.<DD><DL><DT><B>Parameters:</B><DD><CODE>port</CODE> - port to use.<DT><B>Throws:</B><DD><CODE><A HREF="../../java/net/SocketException.html">SocketException</A></CODE> - if the socket could not be opened,               or the socket could not bind to the specified local port.<DD><CODE><A HREF="../../java/lang/SecurityException.html">SecurityException</A></CODE> - if a security manager exists and its               <code>checkListen</code> method doesn't allow the operation.<DT><B>See Also: </B><DD><A HREF="../../java/lang/SecurityManager.html#checkListen(int)"><CODE>SecurityManager.checkListen(int)</CODE></A></DL></DD></DL><HR><A NAME="DatagramSocket(int, java.net.InetAddress)"><!-- --></A><H3>DatagramSocket</H3><PRE>public <B>DatagramSocket</B>(int&nbsp;port,                      <A HREF="../../java/net/InetAddress.html">InetAddress</A>&nbsp;laddr)               throws <A HREF="../../java/net/SocketException.html">SocketException</A></PRE><DL><DD>Creates a datagram socket, bound to the specified local address.  The local port must be between 0 and 65535 inclusive.  <p>If there is a security manager,  its <code>checkListen</code> method is first called with the <code>port</code> argument as its argument to ensure the operation is allowed.  This could result in a SecurityException.<DD><DL><DT><B>Parameters:</B><DD><CODE>port</CODE> - local port to use<DD><CODE>laddr</CODE> - local address to bind<DT><B>Throws:</B><DD><CODE><A HREF="../../java/net/SocketException.html">SocketException</A></CODE> - if the socket could not be opened,               or the socket could not bind to the specified local port.<DD><CODE><A HREF="../../java/lang/SecurityException.html">SecurityException</A></CODE> - if a security manager exists and its               <code>checkListen</code> method doesn't allow the operation.<DT><B>Since: </B><DD>JDK1.1</DD><DT><B>See Also: </B><DD><A HREF="../../java/lang/SecurityManager.html#checkListen(int)"><CODE>SecurityManager.checkListen(int)</CODE></A></DL></DD></DL><!-- ============ METHOD DETAIL ========== --><A NAME="method_detail"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"><TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"><TD COLSPAN=1><FONT SIZE="+2"><B>Method Detail</B></FONT></TD></TR></TABLE><A NAME="connect(java.net.InetAddress, int)"><!-- --></A><H3>connect</H3><PRE>public void <B>connect</B>(<A HREF="../../java/net/InetAddress.html">InetAddress</A>&nbsp;address,                    int&nbsp;port)</PRE><DL><DD>Connects the socket to a remote address for this socket. When a socket is connected to a remote address, packets may only be sent to or received from that address. By default a datagram socket is not connected. <p>A caller's permission to send and receive datagrams to a given host and port are checked at connect time. When a socket is connected, receive and send <b>will not perform any security checks</b> on incoming and outgoing packets, other than matching the packet's and the socket's address and port. On a send operation, if the packet's address is set and the packet's address and the socket's address do not match, an IllegalArgumentException will be thrown. A socket connected to a multicast address may only be used to send packets.<DD><DL><DT><B>Parameters:</B><DD><CODE>address</CODE> - the remote address for the socket<DD><CODE>port</CODE> - the remote port for the socket.<DT><B>Throws:</B><DD><CODE><A HREF="../../java/lang/IllegalArgumentException.html">IllegalArgumentException</A></CODE> - if the address is invalid or the port is out of range.<DD><CODE><A HREF="../../java/lang/SecurityException.html">SecurityException</A></CODE> - if the caller is not allowed to send datagrams to and receive datagrams from the address and port.<DT><B>See Also: </B><DD><A HREF="../../java/net/DatagramSocket.html#disconnect()"><CODE>disconnect()</CODE></A>, <A HREF="../../java/net/DatagramSocket.html#send(java.net.DatagramPacket)"><CODE>send(java.net.DatagramPacket)</CODE></A>, <A HREF="../../java/net/DatagramSocket.html#receive(java.net.DatagramPacket)"><CODE>receive(java.net.DatagramPacket)</CODE></A></DL></DD></DL><HR><A NAME="disconnect()"><!-- --></A><H3>disconnect</H3><PRE>public void <B>disconnect</B>()</PRE><DL><DD>Disconnects the socket. This does nothing if the socket is not connected.<DD><DL><DT><B>See Also: </B><DD><A HREF="../../java/net/DatagramSocket.html#connect(java.net.InetAddress, int)"><CODE>connect(java.net.InetAddress, int)</CODE></A></DL></DD></DL><HR><A NAME="getInetAddress()"><!-- --></A><H3>getInetAddress</H3><PRE>public <A HREF="../../java/net/InetAddress.html">InetAddress</A> <B>getInetAddress</B>()</PRE><DL><DD>Returns the address to which this socket is connected. Returns null if the socket is not connected.<DD><DL><DT><B>Returns:</B><DD>the address to which this socket is connected.</DL></DD></DL><HR><A NAME="getPort()"><!-- --></A><H3>getPort</H3><PRE>public int <B>getPort</B>()</PRE><DL><DD>Returns the port for this socket. Returns -1 if the socket is not connected.<DD><DL><DT><B>Returns:</B><DD>the port to which this socket is connected.</DL></DD></DL><HR><A NAME="send(java.net.DatagramPacket)"><!-- --></A><H3>send</H3><PRE>public void <B>send</B>(<A HREF="../../java/net/DatagramPacket.html">DatagramPacket</A>&nbsp;p)          throws <A HREF="../../java/io/IOException.html">IOException</A></PRE><DL><DD>Sends a datagram packet from this socket. The <code>DatagramPacket</code> includes information indicating the data to be sent, its length, the IP address of the remote host, and the port number on the remote host. <p>If there is a security manager, and the socket is not currently connected to a remote address, this method first performs some security checks. First, if <code>p.getAddress().isMulticastAddress()</code> is true, this method calls the security manager's <code>checkMulticast</code> method with <code>p.getAddress()</code> as its argument. If the evaluation of that expression is false, this method instead calls the security manager's  <code>checkConnect</code> method with arguments <code>p.getAddress().getHostAddress()</code> and <code>p.getPort()</code>. Each call to a security manager method could result in a SecurityException if the operation is not allowed.<DD><DL><DT><B>Parameters:</B><DD><CODE>p</CODE> - the <code>DatagramPacket</code> to be sent.<DT><B>Throws:</B><DD><CODE><A HREF="../../java/io/IOException.html">IOException</A></CODE> - if an I/O error occurs.<DD><CODE><A HREF="../../java/lang/SecurityException.html">SecurityException</A></CODE> - if a security manager exists and its               <code>checkMulticast</code> or <code>checkConnect</code>              method doesn't allow the send.<DT><B>See Also: </B><DD><A HREF="../../java/net/DatagramPacket.html"><CODE>DatagramPacket</CODE></A>, <A HREF="../../java/lang/SecurityManager.html#checkMulticast(java.net.InetAddress)"><CODE>SecurityManager.checkMulticast(InetAddress)</CODE></A>, <A HREF="../../java/lang/SecurityManager.html#checkConnect(java.lang.String, int)"><CODE>SecurityManager.checkConnect(java.lang.String, int)</CODE></A></DL></DD></DL><HR><A NAME="receive(java.net.DatagramPacket)"><!-- --></A><H3>receive</H3><PRE>public void <B>receive</B>(<A HREF="../../java/net/DatagramPacket.html">DatagramPacket</A>&nbsp;p)             throws <A HREF="../../java/io/IOException.html">IOException</A></PRE><DL><DD>Receives a datagram packet from this socket. When this method returns, the <code>DatagramPacket</code>'s buffer is filled with the data received. The datagram packet also contains the sender's IP address, and the port number on the sender's machine. <p> This method blocks until a datagram is received. The <code>length</code> field of the datagram packet object contains the length of the received message. If the message is longer than the packet's length, the message is truncated.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -