LocalSocket
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.
Summary
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 | |
---|---|
Constants
SOCKET_DGRAM
public static final int SOCKET_DGRAM
Datagram socket type
Constant Value: 1 (0x00000001)
SOCKET_SEQPACKET
public static final int SOCKET_SEQPACKET
Sequential packet socket type
Constant Value: 3 (0x00000003)
SOCKET_STREAM
public static final int SOCKET_STREAM
Stream socket type
Constant Value: 2 (0x00000002)
Public constructors
LocalSocket
public LocalSocket ()
Creates a AF_LOCAL/UNIX domain stream socket.
LocalSocket
public 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 |
Public methods
bind
public 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 | |
---|---|
|
java.io.IOException |
IOException |
close
public void close ()
Closes the socket.
Throws | |
---|---|
|
java.io.IOException |
IOException |
connect
public void connect (LocalSocketAddress endpoint, int timeout)
Parameters | |
---|---|
endpoint |
LocalSocketAddress |
timeout |
int |
Throws | |
---|---|
IOException |
connect
public 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. |
getAncillaryFileDescriptors
public 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 | |
---|---|
|
java.io.IOException |
IOException |
getFileDescriptor
public FileDescriptor getFileDescriptor ()
Returns file descriptor or null if not yet open/already closed
Returns | |
---|---|
FileDescriptor |
fd or null |
getInputStream
public InputStream getInputStream ()
Retrieves the input stream for this instance. Closing this stream is equivalent to closing
the entire socket and its associated streams using close()
.
Returns | |
---|---|
InputStream |
input stream |
Throws | |
---|---|
IOException |
if socket has been closed or cannot be created. |
getLocalSocketAddress
public LocalSocketAddress getLocalSocketAddress ()
Retrieves the name that this socket is bound to, if any.
Returns | |
---|---|
LocalSocketAddress |
Local address or null if anonymous |
getOutputStream
public OutputStream getOutputStream ()
Retrieves the output stream for this instance. Closing this stream is equivalent to closing
the entire socket and its associated streams using close()
.
Returns | |
---|---|
OutputStream |
output stream |
Throws | |
---|---|
IOException |
if socket has been closed or cannot be created. |
getPeerCredentials
public Credentials getPeerCredentials ()
Retrieves the credentials of this socket's peer. Only valid on connected sockets.
Returns | |
---|---|
Credentials |
non-null; peer credentials |
Throws | |
---|---|
|
java.io.IOException |
IOException |
getReceiveBufferSize
public int getReceiveBufferSize ()
Returns | |
---|---|
int |
Throws | |
---|---|
IOException |
getRemoteSocketAddress
public LocalSocketAddress getRemoteSocketAddress ()
Returns | |
---|---|
LocalSocketAddress |
getSendBufferSize
public int getSendBufferSize ()
Returns | |
---|---|
int |
Throws | |
---|---|
IOException |
setFileDescriptorsForSend
public 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. |
setReceiveBufferSize
public void setReceiveBufferSize (int size)
Parameters | |
---|---|
size |
int |
Throws | |
---|---|
IOException |
setSendBufferSize
public void setSendBufferSize (int n)
Parameters | |
---|---|
n |
int |
Throws | |
---|---|
IOException |
setSoTimeout
public void setSoTimeout (int n)
Parameters | |
---|---|
n |
int |
Throws | |
---|---|
IOException |
shutdownInput
public void shutdownInput ()
Shuts down the input side of the socket.
Throws | |
---|---|
|
java.io.IOException |
IOException |
shutdownOutput
public void shutdownOutput ()
Shuts down the output side of the socket.
Throws | |
---|---|
|
java.io.IOException |
IOException |
toString
public String toString ()
Returns a string representation of the object.
Returns | |
---|---|
String |
a string representation of the object. |