本文整理了Java中java.net.Socket.checkOpenAndCreate()
方法的一些代码示例,展示了Socket.checkOpenAndCreate()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Socket.checkOpenAndCreate()
方法的具体详情如下:
包路径:java.net.Socket
类名称:Socket
方法名:checkOpenAndCreate
[英]Checks whether the socket is closed, and throws an exception. Otherwise creates the underlying SocketImpl.
[中]检查套接字是否已关闭,并引发异常。否则将创建底层SocketImpl。
代码示例来源:origin: robovm/robovm
/**
* Returns this socket's {@link SocketOptions#SO_TIMEOUT receive timeout}.
*/
public synchronized int getSoTimeout() throws SocketException {
checkOpenAndCreate(true);
return (Integer) impl.getOption(SocketOptions.SO_TIMEOUT);
}
代码示例来源:origin: robovm/robovm
/**
* Sets this socket's {@link SocketOptions#SO_TIMEOUT read timeout} in milliseconds.
* Use 0 for no timeout.
* To take effect, this option must be set before the blocking method was called.
*/
public synchronized void setSoTimeout(int timeout) throws SocketException {
checkOpenAndCreate(true);
if (timeout < 0) {
throw new IllegalArgumentException("timeout < 0");
}
impl.setOption(SocketOptions.SO_TIMEOUT, Integer.valueOf(timeout));
}
代码示例来源:origin: robovm/robovm
/**
* Returns this socket's {@link SocketOptions#SO_REUSEADDR} setting.
*/
public boolean getReuseAddress() throws SocketException {
checkOpenAndCreate(true);
return (Boolean) impl.getOption(SocketOptions.SO_REUSEADDR);
}
代码示例来源:origin: robovm/robovm
/**
* Returns this socket's {@link SocketOptions#SO_KEEPALIVE} setting.
*/
public boolean getKeepAlive() throws SocketException {
checkOpenAndCreate(true);
return (Boolean) impl.getOption(SocketOptions.SO_KEEPALIVE);
}
代码示例来源:origin: robovm/robovm
/**
* Returns this socket's {@link SocketOptions#SO_RCVBUF receive buffer size}.
*/
public synchronized int getReceiveBufferSize() throws SocketException {
checkOpenAndCreate(true);
return (Integer) impl.getOption(SocketOptions.SO_RCVBUF);
}
代码示例来源:origin: robovm/robovm
/**
* Sets this socket's {@link SocketOptions#SO_REUSEADDR} option.
*/
public void setReuseAddress(boolean reuse) throws SocketException {
checkOpenAndCreate(true);
impl.setOption(SocketOptions.SO_REUSEADDR, Boolean.valueOf(reuse));
}
代码示例来源:origin: robovm/robovm
/**
* Sets this socket's {@link SocketOptions#SO_OOBINLINE} option.
*/
public void setOOBInline(boolean oobinline) throws SocketException {
checkOpenAndCreate(true);
impl.setOption(SocketOptions.SO_OOBINLINE, Boolean.valueOf(oobinline));
}
代码示例来源:origin: robovm/robovm
/**
* Sets this socket's {@link SocketOptions#IP_TOS} value for every packet sent by this socket.
*/
public void setTrafficClass(int value) throws SocketException {
checkOpenAndCreate(true);
if (value < 0 || value > 255) {
throw new IllegalArgumentException("Value doesn't fit in an unsigned byte: " + value);
}
impl.setOption(SocketOptions.IP_TOS, Integer.valueOf(value));
}
代码示例来源:origin: robovm/robovm
/**
* Returns this socket's {@see SocketOptions#IP_TOS} setting.
*/
public int getTrafficClass() throws SocketException {
checkOpenAndCreate(true);
return (Integer) impl.getOption(SocketOptions.IP_TOS);
}
代码示例来源:origin: robovm/robovm
/**
* Returns this socket's {@code SocketOptions#TCP_NODELAY} setting.
*/
public boolean getTcpNoDelay() throws SocketException {
checkOpenAndCreate(true);
return (Boolean) impl.getOption(SocketOptions.TCP_NODELAY);
}
代码示例来源:origin: robovm/robovm
/**
* Sets this socket's {@link SocketOptions#SO_KEEPALIVE} option.
*/
public void setKeepAlive(boolean keepAlive) throws SocketException {
if (impl != null) {
checkOpenAndCreate(true);
impl.setOption(SocketOptions.SO_KEEPALIVE, Boolean.valueOf(keepAlive));
}
}
代码示例来源:origin: robovm/robovm
/**
* Sets this socket's {@link SocketOptions#SO_SNDBUF send buffer size}.
*/
public synchronized void setSendBufferSize(int size) throws SocketException {
checkOpenAndCreate(true);
if (size < 1) {
throw new IllegalArgumentException("size < 1");
}
impl.setOption(SocketOptions.SO_SNDBUF, Integer.valueOf(size));
}
代码示例来源:origin: robovm/robovm
/**
* Sets this socket's {@link SocketOptions#TCP_NODELAY} option.
*/
public void setTcpNoDelay(boolean on) throws SocketException {
checkOpenAndCreate(true);
impl.setOption(SocketOptions.TCP_NODELAY, Boolean.valueOf(on));
}
代码示例来源:origin: robovm/robovm
/**
* Returns this socket's {@link SocketOptions#SO_OOBINLINE} setting.
*/
public boolean getOOBInline() throws SocketException {
checkOpenAndCreate(true);
return (Boolean) impl.getOption(SocketOptions.SO_OOBINLINE);
}
代码示例来源:origin: robovm/robovm
/**
* Returns this socket's {@link SocketOptions#SO_SNDBUF send buffer size}.
*/
public synchronized int getSendBufferSize() throws SocketException {
checkOpenAndCreate(true);
return (Integer) impl.getOption(SocketOptions.SO_SNDBUF);
}
代码示例来源:origin: robovm/robovm
/**
* Sets this socket's {@link SocketOptions#SO_RCVBUF receive buffer size}.
*/
public synchronized void setReceiveBufferSize(int size) throws SocketException {
checkOpenAndCreate(true);
if (size < 1) {
throw new IllegalArgumentException("size < 1");
}
impl.setOption(SocketOptions.SO_RCVBUF, Integer.valueOf(size));
}
代码示例来源:origin: robovm/robovm
/**
* Returns this socket's {@link SocketOptions#SO_LINGER linger} timeout in seconds, or -1
* for no linger (i.e. {@code close} will return immediately).
*/
public int getSoLinger() throws SocketException {
checkOpenAndCreate(true);
// The RI explicitly guarantees this idiocy in the SocketOptions.setOption documentation.
Object value = impl.getOption(SocketOptions.SO_LINGER);
if (value instanceof Integer) {
return (Integer) value;
} else {
return -1;
}
}
代码示例来源:origin: robovm/robovm
/**
* Sets this socket's {@link SocketOptions#SO_LINGER linger} timeout in seconds.
* If {@code on} is false, {@code timeout} is irrelevant.
*/
public void setSoLinger(boolean on, int timeout) throws SocketException {
checkOpenAndCreate(true);
// The RI explicitly guarantees this idiocy in the SocketOptions.setOption documentation.
if (on && timeout < 0) {
throw new IllegalArgumentException("timeout < 0");
}
if (on) {
impl.setOption(SocketOptions.SO_LINGER, Integer.valueOf(timeout));
} else {
impl.setOption(SocketOptions.SO_LINGER, Boolean.FALSE);
}
}
代码示例来源:origin: robovm/robovm
/**
* Returns an input stream to read data from this socket.
*
* @return the byte-oriented input stream.
* @throws IOException
* if an error occurs while creating the input stream or the
* socket is in an invalid state.
*/
public InputStream getInputStream() throws IOException {
checkOpenAndCreate(false);
if (isInputShutdown()) {
throw new SocketException("Socket input is shutdown");
}
return impl.getInputStream();
}
代码示例来源:origin: robovm/robovm
/**
* Returns an output stream to write data into this socket.
*
* @return the byte-oriented output stream.
* @throws IOException
* if an error occurs while creating the output stream or the
* socket is in an invalid state.
*/
public OutputStream getOutputStream() throws IOException {
checkOpenAndCreate(false);
if (isOutputShutdown()) {
throw new SocketException("Socket output is shutdown");
}
return impl.getOutputStream();
}
内容来源于网络,如有侵权,请联系作者删除!