public class LocalSocket extends Object implements Closeable
Modifier and Type | Field and Description |
---|---|
static int |
SOCKET_DGRAM
Datagram socket type
|
static int |
SOCKET_SEQPACKET
Sequential packet socket type
|
static int |
SOCKET_STREAM
Stream socket type
|
Constructor and Description |
---|
LocalSocket()
Creates a AF_LOCAL/UNIX domain stream socket.
|
LocalSocket(FileDescriptor fd)
Creates a AF_LOCAL/UNIX domain stream socket with FileDescriptor.
|
LocalSocket(int sockType)
Creates a AF_LOCAL/UNIX domain stream socket with given socket type
|
Modifier and Type | Method and Description |
---|---|
void |
bind(LocalSocketAddress bindpoint)
Binds this socket to an endpoint name.
|
void |
close()
Closes the socket.
|
void |
connect(LocalSocketAddress endpoint)
Connects this socket to an endpoint.
|
void |
connect(LocalSocketAddress endpoint,
int timeout) |
FileDescriptor[] |
getAncillaryFileDescriptors()
Retrieves a set of file descriptors that a peer has sent through
an ancillary message.
|
FileDescriptor |
getFileDescriptor()
Returns file descriptor or null if not yet open/already closed
|
InputStream |
getInputStream()
Retrieves the input stream for this instance.
|
LocalSocketAddress |
getLocalSocketAddress()
Retrieves the name that this socket is bound to, if any.
|
OutputStream |
getOutputStream()
Retrieves the output stream for this instance.
|
Credentials |
getPeerCredentials()
Retrieves the credentials of this socket's peer.
|
int |
getReceiveBufferSize() |
LocalSocketAddress |
getRemoteSocketAddress() |
int |
getSendBufferSize() |
int |
getSoTimeout() |
boolean |
isBound() |
boolean |
isClosed() |
boolean |
isConnected() |
boolean |
isInputShutdown() |
boolean |
isOutputShutdown() |
void |
setFileDescriptorsForSend(FileDescriptor[] fds)
Enqueues a set of file descriptors to send to the peer.
|
void |
setReceiveBufferSize(int size) |
void |
setSendBufferSize(int n) |
void |
setSoTimeout(int n) |
void |
shutdownInput()
Shuts down the input side of the socket.
|
void |
shutdownOutput()
Shuts down the output side of the socket.
|
String |
toString()
Returns a string representation of the object.
|
public static final int SOCKET_DGRAM
public static final int SOCKET_STREAM
public static final int SOCKET_SEQPACKET
public LocalSocket()
public LocalSocket(int sockType)
sockType
- either SOCKET_DGRAM
, SOCKET_STREAM
or SOCKET_SEQPACKET
public LocalSocket(FileDescriptor fd) throws IOException
IOException
public String toString()
toString
method returns a string that
"textually represents" this object. The result should
be a concise but informative representation that is easy for a
person to read.
It is recommended that all subclasses override this method.
The toString
method for class Object
returns a string consisting of the name of the class of which the
object is an instance, the at-sign character `@
', and
the unsigned hexadecimal representation of the hash code of the
object. In other words, this method returns a string equal to the
value of:
getClass().getName() + '@' + Integer.toHexString(hashCode())
public void connect(LocalSocketAddress endpoint) throws IOException
endpoint
- endpoint addressIOException
- if socket is in invalid state or the address does
not exist.public void bind(LocalSocketAddress bindpoint) throws IOException
bindpoint
- endpoint addressIOException
public LocalSocketAddress getLocalSocketAddress()
public InputStream getInputStream() throws IOException
IOException
- if socket has been closed or cannot be created.public OutputStream getOutputStream() throws IOException
IOException
- if socket has been closed or cannot be created.public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
public void shutdownInput() throws IOException
IOException
public void shutdownOutput() throws IOException
IOException
public void setReceiveBufferSize(int size) throws IOException
IOException
public int getReceiveBufferSize() throws IOException
IOException
public void setSoTimeout(int n) throws IOException
IOException
public int getSoTimeout() throws IOException
IOException
public void setSendBufferSize(int n) throws IOException
IOException
public int getSendBufferSize() throws IOException
IOException
public LocalSocketAddress getRemoteSocketAddress()
public boolean isConnected()
public boolean isClosed()
public boolean isBound()
public boolean isOutputShutdown()
public boolean isInputShutdown()
public void connect(LocalSocketAddress endpoint, int timeout) throws IOException
IOException
public void setFileDescriptorsForSend(FileDescriptor[] fds)
fds
- non-null; file descriptors to send.public FileDescriptor[] getAncillaryFileDescriptors() throws IOException
IOException
public Credentials getPeerCredentials() throws IOException
IOException
public FileDescriptor getFileDescriptor()