src/share/classes/java/net/Socket.java

Print this page




 136                                   epoint.getPort());
 137             }
 138             impl = type == Proxy.Type.SOCKS ? new SocksSocketImpl(p)
 139                                             : new HttpConnectSocketImpl(p);
 140             impl.setSocket(this);
 141         } else {
 142             if (p == Proxy.NO_PROXY) {
 143                 if (factory == null) {
 144                     impl = new PlainSocketImpl();
 145                     impl.setSocket(this);
 146                 } else
 147                     setImpl();
 148             } else
 149                 throw new IllegalArgumentException("Invalid Proxy");
 150         }
 151     }
 152 
 153     /**
 154      * Creates an unconnected Socket with a user-specified
 155      * SocketImpl.
 156      * <P>
 157      * @param impl an instance of a <B>SocketImpl</B>
 158      * the subclass wishes to use on the Socket.
 159      *
 160      * @exception SocketException if there is an error in the underlying protocol,
 161      * such as a TCP error.
 162      * @since   JDK1.1
 163      */
 164     protected Socket(SocketImpl impl) throws SocketException {
 165         this.impl = impl;
 166         if (impl != null) {
 167             checkOldImpl();
 168             this.impl.setSocket(this);
 169         }
 170     }
 171 
 172     /**
 173      * Creates a stream socket and connects it to the specified port
 174      * number on the named host.
 175      * <p>
 176      * If the specified host is {@code null} it is the equivalent of


1228      * used by the platform's networking code as a hint for the size to set
1229      * the underlying network I/O buffers.
1230      *
1231      * <p>Increasing the receive buffer size can increase the performance of
1232      * network I/O for high-volume connection, while decreasing it can
1233      * help reduce the backlog of incoming data.
1234      *
1235      * <p>Because {@link SocketOptions#SO_RCVBUF SO_RCVBUF} is a hint,
1236      * applications that want to verify what size the buffers were set to
1237      * should call {@link #getReceiveBufferSize()}.
1238      *
1239      * <p>The value of {@link SocketOptions#SO_RCVBUF SO_RCVBUF} is also used
1240      * to set the TCP receive window that is advertized to the remote peer.
1241      * Generally, the window size can be modified at any time when a socket is
1242      * connected. However, if a receive window larger than 64K is required then
1243      * this must be requested <B>before</B> the socket is connected to the
1244      * remote peer. There are two cases to be aware of:
1245      * <ol>
1246      * <li>For sockets accepted from a ServerSocket, this must be done by calling
1247      * {@link ServerSocket#setReceiveBufferSize(int)} before the ServerSocket
1248      * is bound to a local address.<p></li>
1249      * <li>For client sockets, setReceiveBufferSize() must be called before
1250      * connecting the socket to its remote peer.</li></ol>
1251      * @param size the size to which to set the receive buffer
1252      * size. This value must be greater than 0.
1253      *
1254      * @exception IllegalArgumentException if the value is 0 or is
1255      * negative.
1256      *
1257      * @exception SocketException if there is an error
1258      * in the underlying protocol, such as a TCP error.
1259      *
1260      * @see #getReceiveBufferSize()
1261      * @see ServerSocket#setReceiveBufferSize(int)
1262      * @since 1.2
1263      */
1264     public synchronized void setReceiveBufferSize(int size)
1265     throws SocketException{
1266         if (size <= 0) {
1267             throw new IllegalArgumentException("invalid receive size");
1268         }




 136                                   epoint.getPort());
 137             }
 138             impl = type == Proxy.Type.SOCKS ? new SocksSocketImpl(p)
 139                                             : new HttpConnectSocketImpl(p);
 140             impl.setSocket(this);
 141         } else {
 142             if (p == Proxy.NO_PROXY) {
 143                 if (factory == null) {
 144                     impl = new PlainSocketImpl();
 145                     impl.setSocket(this);
 146                 } else
 147                     setImpl();
 148             } else
 149                 throw new IllegalArgumentException("Invalid Proxy");
 150         }
 151     }
 152 
 153     /**
 154      * Creates an unconnected Socket with a user-specified
 155      * SocketImpl.
 156      *
 157      * @param impl an instance of a <B>SocketImpl</B>
 158      * the subclass wishes to use on the Socket.
 159      *
 160      * @exception SocketException if there is an error in the underlying protocol,
 161      * such as a TCP error.
 162      * @since   JDK1.1
 163      */
 164     protected Socket(SocketImpl impl) throws SocketException {
 165         this.impl = impl;
 166         if (impl != null) {
 167             checkOldImpl();
 168             this.impl.setSocket(this);
 169         }
 170     }
 171 
 172     /**
 173      * Creates a stream socket and connects it to the specified port
 174      * number on the named host.
 175      * <p>
 176      * If the specified host is {@code null} it is the equivalent of


1228      * used by the platform's networking code as a hint for the size to set
1229      * the underlying network I/O buffers.
1230      *
1231      * <p>Increasing the receive buffer size can increase the performance of
1232      * network I/O for high-volume connection, while decreasing it can
1233      * help reduce the backlog of incoming data.
1234      *
1235      * <p>Because {@link SocketOptions#SO_RCVBUF SO_RCVBUF} is a hint,
1236      * applications that want to verify what size the buffers were set to
1237      * should call {@link #getReceiveBufferSize()}.
1238      *
1239      * <p>The value of {@link SocketOptions#SO_RCVBUF SO_RCVBUF} is also used
1240      * to set the TCP receive window that is advertized to the remote peer.
1241      * Generally, the window size can be modified at any time when a socket is
1242      * connected. However, if a receive window larger than 64K is required then
1243      * this must be requested <B>before</B> the socket is connected to the
1244      * remote peer. There are two cases to be aware of:
1245      * <ol>
1246      * <li>For sockets accepted from a ServerSocket, this must be done by calling
1247      * {@link ServerSocket#setReceiveBufferSize(int)} before the ServerSocket
1248      * is bound to a local address.</li>
1249      * <li>For client sockets, setReceiveBufferSize() must be called before
1250      * connecting the socket to its remote peer.</li></ol>
1251      * @param size the size to which to set the receive buffer
1252      * size. This value must be greater than 0.
1253      *
1254      * @exception IllegalArgumentException if the value is 0 or is
1255      * negative.
1256      *
1257      * @exception SocketException if there is an error
1258      * in the underlying protocol, such as a TCP error.
1259      *
1260      * @see #getReceiveBufferSize()
1261      * @see ServerSocket#setReceiveBufferSize(int)
1262      * @since 1.2
1263      */
1264     public synchronized void setReceiveBufferSize(int size)
1265     throws SocketException{
1266         if (size <= 0) {
1267             throw new IllegalArgumentException("invalid receive size");
1268         }