Package one.nio.net
Class Socket
- java.lang.Object
-
- one.nio.net.Socket
-
- All Implemented Interfaces:
Closeable,AutoCloseable,ByteChannel,Channel,ReadableByteChannel,WritableByteChannel
- Direct Known Subclasses:
SelectableJavaSocket
public abstract class Socket extends Object implements ByteChannel
-
-
Field Summary
Fields Modifier and Type Field Description static intAF_INETstatic intAF_INET6static intAF_UNIXstatic intIPTOS_LOWDELAYstatic intIPTOS_MINCOSTstatic intIPTOS_RELIABILITYstatic intIPTOS_THROUGHPUTstatic intMSG_DONTROUTEstatic intMSG_DONTWAITstatic intMSG_MOREstatic intMSG_OOBstatic intMSG_PEEKstatic intMSG_TRUNCstatic intMSG_WAITALLstatic intNO_PORTstatic intSO_BROADCASTstatic intSO_BSDCOMPATstatic intSO_DEBUGstatic intSO_DONTROUTEstatic intSO_ERRORstatic intSO_KEEPALIVEstatic intSO_LINGERstatic intSO_NO_CHECKstatic intSO_OOBINLINEstatic intSO_PASSCREDstatic intSO_PEERCREDstatic intSO_PRIORITYstatic intSO_RCVBUFstatic intSO_RCVLOWATstatic intSO_RCVTIMEOstatic intSO_REUSEADDRstatic intSO_REUSEPORTstatic intSO_SNDBUFstatic intSO_SNDLOWATstatic intSO_SNDTIMEOstatic intSO_TYPEstatic intSOCK_DGRAMstatic intSOCK_RAWstatic intSOCK_RDMstatic intSOCK_SEQPACKETstatic intSOCK_STREAMstatic intSOL_IPstatic intSOL_IPV6static intSOL_SOCKETstatic intSOL_TCPstatic intSOL_UDPstatic intTCP_CONGESTIONstatic intTCP_CORKstatic intTCP_DEFER_ACCEPTstatic intTCP_INFOstatic intTCP_KEEPCNTstatic intTCP_KEEPIDLEstatic intTCP_KEEPINTVLstatic intTCP_LINGER2static intTCP_MAXSEGstatic intTCP_NODELAYstatic intTCP_QUICKACKstatic intTCP_SYNCNTstatic intTCP_USER_TIMEOUTstatic intTCP_WINDOW_CLAMP
-
Constructor Summary
Constructors Constructor Description Socket()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract Socketaccept()SocketacceptNonBlocking()voidbind(String host, int port, int backlog)abstract voidbind(InetAddress address, int port, int backlog)static SocketbindInet(InetAddress address, int port, int backlog)static SocketbindUnix(File unixPath, int backlog)abstract voidclose()voidconnect(String host, int port)abstract voidconnect(InetAddress address, int port)static SocketconnectInet(InetAddress address, int port)static SocketconnectUnix(File unixPath)static Socketcreate()static SocketcreateDatagramSocket()static SocketcreateServerSocket()static SocketcreateUnixSocket(int type)static SocketfromFD(int fd)abstract booleangetDeferAccept()abstract booleangetKeepAlive()abstract InetSocketAddressgetLocalAddress()abstract booleangetNoDelay()abstract byte[]getOption(int level, int option)abstract intgetRecvBuffer()abstract InetSocketAddressgetRemoteAddress()abstract booleangetReuseAddr()abstract booleangetReusePort()abstract intgetSendBuffer()abstract SslContextgetSslContext()abstract <T> TgetSslOption(SslOption<T> option)abstract booleangetTcpFastOpen()abstract intgetTimeout()abstract intgetTos()voidhandshake()abstract booleanisBlocking()abstract booleanisOpen()abstract voidlisten(int backlog)intread(byte[] data, int offset, int count)abstract intread(byte[] data, int offset, int count, int flags)abstract voidreadFully(byte[] data, int offset, int count)abstract intreadRaw(long buf, int count, int flags)abstract InetSocketAddressrecv(ByteBuffer dst, int flags)abstract intrecvMsg(Msg msg, int flags)intsend(ByteBuffer data, int flags, String host, int port)abstract intsend(ByteBuffer src, int flags, InetAddress address, int port)abstract longsendFile(RandomAccessFile file, long offset, long count)abstract intsendMsg(Msg msg, int flags)abstract voidsetBlocking(boolean blocking)abstract voidsetDeferAccept(boolean deferAccept)abstract voidsetKeepAlive(boolean keepAlive)abstract voidsetNoDelay(boolean noDelay)abstract booleansetOption(int level, int option, byte[] value)abstract voidsetRecvBuffer(int recvBuf)abstract voidsetReuseAddr(boolean reuseAddr, boolean reusePort)abstract voidsetSendBuffer(int sendBuf)abstract voidsetTcpFastOpen(boolean tcpFastOpen)abstract voidsetTimeout(int timeout)abstract voidsetTos(int tos)abstract SocketsslUnwrap()abstract SocketsslWrap(SslContext context)intwrite(byte[] data, int offset, int count)abstract intwrite(byte[] data, int offset, int count, int flags)abstract voidwriteFully(byte[] data, int offset, int count)abstract intwriteRaw(long buf, int count, int flags)-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.nio.channels.ReadableByteChannel
read
-
Methods inherited from interface java.nio.channels.WritableByteChannel
write
-
-
-
-
Field Detail
-
AF_UNIX
public static final int AF_UNIX
- See Also:
- Constant Field Values
-
AF_INET
public static final int AF_INET
- See Also:
- Constant Field Values
-
AF_INET6
public static final int AF_INET6
- See Also:
- Constant Field Values
-
SOCK_STREAM
public static final int SOCK_STREAM
- See Also:
- Constant Field Values
-
SOCK_DGRAM
public static final int SOCK_DGRAM
- See Also:
- Constant Field Values
-
SOCK_RAW
public static final int SOCK_RAW
- See Also:
- Constant Field Values
-
SOCK_RDM
public static final int SOCK_RDM
- See Also:
- Constant Field Values
-
SOCK_SEQPACKET
public static final int SOCK_SEQPACKET
- See Also:
- Constant Field Values
-
NO_PORT
public static final int NO_PORT
- See Also:
- Constant Field Values
-
SOL_SOCKET
public static final int SOL_SOCKET
- See Also:
- Constant Field Values
-
SOL_IP
public static final int SOL_IP
- See Also:
- Constant Field Values
-
SOL_IPV6
public static final int SOL_IPV6
- See Also:
- Constant Field Values
-
SOL_TCP
public static final int SOL_TCP
- See Also:
- Constant Field Values
-
SOL_UDP
public static final int SOL_UDP
- See Also:
- Constant Field Values
-
MSG_OOB
public static final int MSG_OOB
- See Also:
- Constant Field Values
-
MSG_PEEK
public static final int MSG_PEEK
- See Also:
- Constant Field Values
-
MSG_DONTROUTE
public static final int MSG_DONTROUTE
- See Also:
- Constant Field Values
-
MSG_TRUNC
public static final int MSG_TRUNC
- See Also:
- Constant Field Values
-
MSG_DONTWAIT
public static final int MSG_DONTWAIT
- See Also:
- Constant Field Values
-
MSG_WAITALL
public static final int MSG_WAITALL
- See Also:
- Constant Field Values
-
MSG_MORE
public static final int MSG_MORE
- See Also:
- Constant Field Values
-
IPTOS_MINCOST
public static final int IPTOS_MINCOST
- See Also:
- Constant Field Values
-
IPTOS_RELIABILITY
public static final int IPTOS_RELIABILITY
- See Also:
- Constant Field Values
-
IPTOS_THROUGHPUT
public static final int IPTOS_THROUGHPUT
- See Also:
- Constant Field Values
-
IPTOS_LOWDELAY
public static final int IPTOS_LOWDELAY
- See Also:
- Constant Field Values
-
SO_DEBUG
public static final int SO_DEBUG
- See Also:
- Constant Field Values
-
SO_REUSEADDR
public static final int SO_REUSEADDR
- See Also:
- Constant Field Values
-
SO_TYPE
public static final int SO_TYPE
- See Also:
- Constant Field Values
-
SO_ERROR
public static final int SO_ERROR
- See Also:
- Constant Field Values
-
SO_DONTROUTE
public static final int SO_DONTROUTE
- See Also:
- Constant Field Values
-
SO_BROADCAST
public static final int SO_BROADCAST
- See Also:
- Constant Field Values
-
SO_SNDBUF
public static final int SO_SNDBUF
- See Also:
- Constant Field Values
-
SO_RCVBUF
public static final int SO_RCVBUF
- See Also:
- Constant Field Values
-
SO_KEEPALIVE
public static final int SO_KEEPALIVE
- See Also:
- Constant Field Values
-
SO_OOBINLINE
public static final int SO_OOBINLINE
- See Also:
- Constant Field Values
-
SO_NO_CHECK
public static final int SO_NO_CHECK
- See Also:
- Constant Field Values
-
SO_PRIORITY
public static final int SO_PRIORITY
- See Also:
- Constant Field Values
-
SO_LINGER
public static final int SO_LINGER
- See Also:
- Constant Field Values
-
SO_BSDCOMPAT
public static final int SO_BSDCOMPAT
- See Also:
- Constant Field Values
-
SO_REUSEPORT
public static final int SO_REUSEPORT
- See Also:
- Constant Field Values
-
SO_PASSCRED
public static final int SO_PASSCRED
- See Also:
- Constant Field Values
-
SO_PEERCRED
public static final int SO_PEERCRED
- See Also:
- Constant Field Values
-
SO_RCVLOWAT
public static final int SO_RCVLOWAT
- See Also:
- Constant Field Values
-
SO_SNDLOWAT
public static final int SO_SNDLOWAT
- See Also:
- Constant Field Values
-
SO_RCVTIMEO
public static final int SO_RCVTIMEO
- See Also:
- Constant Field Values
-
SO_SNDTIMEO
public static final int SO_SNDTIMEO
- See Also:
- Constant Field Values
-
TCP_NODELAY
public static final int TCP_NODELAY
- See Also:
- Constant Field Values
-
TCP_MAXSEG
public static final int TCP_MAXSEG
- See Also:
- Constant Field Values
-
TCP_CORK
public static final int TCP_CORK
- See Also:
- Constant Field Values
-
TCP_KEEPIDLE
public static final int TCP_KEEPIDLE
- See Also:
- Constant Field Values
-
TCP_KEEPINTVL
public static final int TCP_KEEPINTVL
- See Also:
- Constant Field Values
-
TCP_KEEPCNT
public static final int TCP_KEEPCNT
- See Also:
- Constant Field Values
-
TCP_SYNCNT
public static final int TCP_SYNCNT
- See Also:
- Constant Field Values
-
TCP_LINGER2
public static final int TCP_LINGER2
- See Also:
- Constant Field Values
-
TCP_DEFER_ACCEPT
public static final int TCP_DEFER_ACCEPT
- See Also:
- Constant Field Values
-
TCP_WINDOW_CLAMP
public static final int TCP_WINDOW_CLAMP
- See Also:
- Constant Field Values
-
TCP_INFO
public static final int TCP_INFO
- See Also:
- Constant Field Values
-
TCP_QUICKACK
public static final int TCP_QUICKACK
- See Also:
- Constant Field Values
-
TCP_CONGESTION
public static final int TCP_CONGESTION
- See Also:
- Constant Field Values
-
TCP_USER_TIMEOUT
public static final int TCP_USER_TIMEOUT
- See Also:
- Constant Field Values
-
-
Method Detail
-
close
public abstract void close()
-
accept
public abstract Socket accept() throws IOException
- Throws:
IOException
-
connect
public abstract void connect(InetAddress address, int port) throws IOException
- Throws:
IOException
-
bind
public abstract void bind(InetAddress address, int port, int backlog) throws IOException
- Throws:
IOException
-
listen
public abstract void listen(int backlog) throws IOException- Throws:
IOException
-
writeRaw
public abstract int writeRaw(long buf, int count, int flags) throws IOException- Throws:
IOException
-
write
public abstract int write(byte[] data, int offset, int count, int flags) throws IOException- Throws:
IOException
-
writeFully
public abstract void writeFully(byte[] data, int offset, int count) throws IOException- Throws:
IOException
-
send
public abstract int send(ByteBuffer src, int flags, InetAddress address, int port) throws IOException
- Throws:
IOException
-
readRaw
public abstract int readRaw(long buf, int count, int flags) throws IOException- Throws:
IOException
-
read
public abstract int read(byte[] data, int offset, int count, int flags) throws IOException- Throws:
IOException
-
readFully
public abstract void readFully(byte[] data, int offset, int count) throws IOException- Throws:
IOException
-
recv
public abstract InetSocketAddress recv(ByteBuffer dst, int flags) throws IOException
- Throws:
IOException
-
sendFile
public abstract long sendFile(RandomAccessFile file, long offset, long count) throws IOException
- Throws:
IOException
-
sendMsg
public abstract int sendMsg(Msg msg, int flags) throws IOException
- Throws:
IOException
-
recvMsg
public abstract int recvMsg(Msg msg, int flags) throws IOException
- Throws:
IOException
-
setBlocking
public abstract void setBlocking(boolean blocking)
-
isBlocking
public abstract boolean isBlocking()
-
setTimeout
public abstract void setTimeout(int timeout)
-
getTimeout
public abstract int getTimeout()
-
setKeepAlive
public abstract void setKeepAlive(boolean keepAlive)
-
getKeepAlive
public abstract boolean getKeepAlive()
-
setNoDelay
public abstract void setNoDelay(boolean noDelay)
-
getNoDelay
public abstract boolean getNoDelay()
-
setTcpFastOpen
public abstract void setTcpFastOpen(boolean tcpFastOpen)
-
getTcpFastOpen
public abstract boolean getTcpFastOpen()
-
setDeferAccept
public abstract void setDeferAccept(boolean deferAccept)
-
getDeferAccept
public abstract boolean getDeferAccept()
-
setReuseAddr
public abstract void setReuseAddr(boolean reuseAddr, boolean reusePort)
-
getReuseAddr
public abstract boolean getReuseAddr()
-
getReusePort
public abstract boolean getReusePort()
-
setRecvBuffer
public abstract void setRecvBuffer(int recvBuf)
-
getRecvBuffer
public abstract int getRecvBuffer()
-
setSendBuffer
public abstract void setSendBuffer(int sendBuf)
-
getSendBuffer
public abstract int getSendBuffer()
-
setTos
public abstract void setTos(int tos)
-
getTos
public abstract int getTos()
-
getOption
public abstract byte[] getOption(int level, int option)
-
setOption
public abstract boolean setOption(int level, int option, byte[] value)
-
getLocalAddress
public abstract InetSocketAddress getLocalAddress()
-
getRemoteAddress
public abstract InetSocketAddress getRemoteAddress()
-
sslWrap
public abstract Socket sslWrap(SslContext context) throws IOException
- Throws:
IOException
-
sslUnwrap
public abstract Socket sslUnwrap()
-
getSslContext
public abstract SslContext getSslContext()
-
getSslOption
public abstract <T> T getSslOption(SslOption<T> option)
-
acceptNonBlocking
public Socket acceptNonBlocking() throws IOException
- Throws:
IOException
-
connect
public void connect(String host, int port) throws IOException
- Throws:
IOException
-
bind
public void bind(String host, int port, int backlog) throws IOException
- Throws:
IOException
-
send
public int send(ByteBuffer data, int flags, String host, int port) throws IOException
- Throws:
IOException
-
handshake
public void handshake() throws IOException- Throws:
IOException
-
write
public int write(byte[] data, int offset, int count) throws IOException- Throws:
IOException
-
read
public int read(byte[] data, int offset, int count) throws IOException- Throws:
IOException
-
create
public static Socket create() throws IOException
- Throws:
IOException
-
createServerSocket
public static Socket createServerSocket() throws IOException
- Throws:
IOException
-
createDatagramSocket
public static Socket createDatagramSocket() throws IOException
- Throws:
IOException
-
createUnixSocket
public static Socket createUnixSocket(int type) throws IOException
- Throws:
IOException
-
connectInet
public static Socket connectInet(InetAddress address, int port) throws IOException
- Throws:
IOException
-
bindInet
public static Socket bindInet(InetAddress address, int port, int backlog) throws IOException
- Throws:
IOException
-
connectUnix
public static Socket connectUnix(File unixPath) throws IOException
- Throws:
IOException
-
bindUnix
public static Socket bindUnix(File unixPath, int backlog) throws IOException
- Throws:
IOException
-
fromFD
public static Socket fromFD(int fd) throws IOException
- Throws:
IOException
-
-