public
class
LocalSocket
extends Object
implements
Closeable
java.lang.Object | |
↳ | android.net.LocalSocket |
Creates a (non-server) socket in the UNIX-domain namespace. The interface here is not entirely unlike that of java.net.Socket. This class and the streams returned from it may be used from multiple threads.
Constants | |
---|---|
int |
SOCKET_DGRAM
Datagram socket type |
int |
SOCKET_SEQPACKET
Sequential packet socket type |
int |
SOCKET_STREAM
Stream socket type |
Public constructors | |
---|---|
LocalSocket()
Creates a AF_LOCAL/UNIX domain stream socket. |
|
LocalSocket(int sockType)
Creates a AF_LOCAL/UNIX domain stream socket with given socket type |
Public methods | |
---|---|
void
|
bind(LocalSocketAddress bindpoint)
Binds this socket to an endpoint name. |
void
|
close()
Closes the socket. |
void
|
connect(LocalSocketAddress endpoint, int timeout)
|
void
|
connect(LocalSocketAddress endpoint)
Connects this socket to an endpoint. |
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. |
Inherited methods | |
---|---|
From
class
java.lang.Object
| |
From
interface
java.io.Closeable
| |
From
interface
java.lang.AutoCloseable
|
int SOCKET_DGRAM
Datagram socket type
Constant Value: 1 (0x00000001)
int SOCKET_SEQPACKET
Sequential packet socket type
Constant Value: 3 (0x00000003)
int SOCKET_STREAM
Stream socket type
Constant Value: 2 (0x00000002)
LocalSocket (int sockType)
Creates a AF_LOCAL/UNIX domain stream socket with given socket type
Parameters | |
---|---|
sockType |
int :
either SOCKET_DGRAM , SOCKET_STREAM
or SOCKET_SEQPACKET
|
void bind (LocalSocketAddress bindpoint)
Binds this socket to an endpoint name. May only be called on an instance that has not yet been bound.
Parameters | |
---|---|
bindpoint |
LocalSocketAddress :
endpoint address |
Throws | |
---|---|
IOException |
void connect (LocalSocketAddress endpoint, int timeout)
Parameters | |
---|---|
endpoint |
LocalSocketAddress
|
timeout |
int
|
Throws | |
---|---|
IOException |
void connect (LocalSocketAddress endpoint)
Connects this socket to an endpoint. May only be called on an instance that has not yet been connected.
Parameters | |
---|---|
endpoint |
LocalSocketAddress :
endpoint address |
Throws | |
---|---|
IOException |
if socket is in invalid state or the address does not exist. |
FileDescriptor[] getAncillaryFileDescriptors ()
Retrieves a set of file descriptors that a peer has sent through an ancillary message. This method retrieves the most recent set sent, and then returns null until a new set arrives. File descriptors may only be passed along with regular data, so this method can only return a non-null after a read operation.
Returns | |
---|---|
FileDescriptor[] |
null or file descriptor array |
Throws | |
---|---|
IOException |
FileDescriptor getFileDescriptor ()
Returns file descriptor or null if not yet open/already closed
Returns | |
---|---|
FileDescriptor |
fd or null |
InputStream getInputStream ()
Retrieves the input stream for this instance.
Returns | |
---|---|
InputStream |
input stream |
Throws | |
---|---|
IOException |
if socket has been closed or cannot be created. |
LocalSocketAddress getLocalSocketAddress ()
Retrieves the name that this socket is bound to, if any.
Returns | |
---|---|
LocalSocketAddress |
Local address or null if anonymous |
OutputStream getOutputStream ()
Retrieves the output stream for this instance.
Returns | |
---|---|
OutputStream |
output stream |
Throws | |
---|---|
IOException |
if socket has been closed or cannot be created. |
Credentials getPeerCredentials ()
Retrieves the credentials of this socket's peer. Only valid on connected sockets.
Returns | |
---|---|
Credentials |
non-null; peer credentials |
Throws | |
---|---|
IOException |
int getReceiveBufferSize ()
Returns | |
---|---|
int |
Throws | |
---|---|
IOException |
LocalSocketAddress getRemoteSocketAddress ()
Returns | |
---|---|
LocalSocketAddress |
void setFileDescriptorsForSend (FileDescriptor[] fds)
Enqueues a set of file descriptors to send to the peer. The queue is one deep. The file descriptors will be sent with the next write of normal data, and will be delivered in a single ancillary message. See "man 7 unix" SCM_RIGHTS on a desktop Linux machine.
Parameters | |
---|---|
fds |
FileDescriptor :
non-null; file descriptors to send.
|
void setReceiveBufferSize (int size)
Parameters | |
---|---|
size |
int
|
Throws | |
---|---|
IOException |
void setSendBufferSize (int n)
Parameters | |
---|---|
n |
int
|
Throws | |
---|---|
IOException |
void shutdownInput ()
Shuts down the input side of the socket.
Throws | |
---|---|
IOException |
void shutdownOutput ()
Shuts down the output side of the socket.
Throws | |
---|---|
IOException |
String toString ()
Returns a string representation of the object. In general, the
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())
Returns | |
---|---|
String |
a string representation of the object. |