public class LocalSocket extends Object
| 构造器 | 说明 |
|---|---|
LocalSocket(String name,
boolean isServer) |
A parameterized constructor used to create a
LocalSocket instance. |
| 限定符和类型 | 方法 | 说明 |
|---|---|---|
LocalSocket |
acceptSocket() |
Accepts a connection request from the client.
|
void |
closeInputStream() |
Closes the input stream of this socket.
|
void |
closeOutputStream() |
Closes the output stream of this socket.
|
void |
closeSocket() |
Closes the socket after the server and client finish communicating with each other.
|
void |
connectSocket() |
Connects the client socket to a specified address for setting up a connection with the server.
|
FileDescriptor[] |
getAppendedFds() |
Obtains an array of appended file descriptors sent by the peer as additional information.
|
InputStream |
getInputStream() |
Obtains the input stream of this socket.
|
OutputStream |
getOutputStream() |
Obtains the output stream of this socket.
|
SocketCertificates |
getPeerSocketInfo() |
Obtains certificates of the peer socket.
|
FileDescriptor |
getSocketFd() |
Obtains the file descriptor of this socket.
|
String |
getSocketName() |
Obtains the socket name.
|
boolean |
isSocketConnected() |
Checks whether this socket is connected.
|
void |
setAppendedFds(FileDescriptor[] fds) |
Sets an array of appended file descriptors that will be added as additional information to
the common information to be sent to the peer next time.
|
void |
setSocketReadTimeout(int timeout) |
Sets the timeout duration for reading data from the input stream of this socket.
|
public LocalSocket(String name, boolean isServer) throws IOException
LocalSocket instance.
Currently, only a stream socket can be created. If a server socket is to be created, bind and listen operations will be performed during the creation.
name - Indicates the socket name. It cannot be null.isServer - Specifies whether to create a server or client socket. The value true
means to create a server socket, and false means to create a client socket.IllegalArgumentException - Throws this exception if name is null.IOException - Throws this exception if an error occurs during the server socket creation.public void connectSocket()
throws IOException
The address is the name passed in the constructor.
IOException - Throws this exception if the socket connection status is invalid
(for example, already connected) or an error occurs during the socket creation.public LocalSocket acceptSocket() throws IOException
LocalSocket object for communicating with the client.IOException - Throws this exception if an error occurs during the socket creation,
for example, the socket fails to create.public void closeSocket()
throws IOException
IOException - Throws this exception if the socket fails to close.public InputStream getInputStream() throws IOException
IOException - Throws this exception if an error occurs during the socket creation or
the socket has been closed.public OutputStream getOutputStream() throws IOException
IOException - Throws this exception if an error occurs during the socket creation or
the socket has been closed.public void closeInputStream()
throws IOException
IOException - Throws this exception if an error occurs during the socket creation,
for example, the socket fails to create.public void closeOutputStream()
throws IOException
IOException - Throws this exception if an error occurs during the socket creation,
for example, the socket fails to create.public FileDescriptor getSocketFd()
public String getSocketName()
public SocketCertificates getPeerSocketInfo() throws IOException
IOException - Throws this exception if an error occurs during the socket creation,
for example, the socket fails to create.public boolean isSocketConnected()
true if this socket is connected; returns false otherwise.public void setSocketReadTimeout(int timeout)
throws IOException
timeout - Indicates the timeout duration to set, in milliseconds.IOException - Throws this exception if an error occurs during the socket creation,
for example, the socket fails to create.public FileDescriptor[] getAppendedFds() throws IOException
null otherwise.IOException - Throws this exception if an error occurs during the socket creation,
for example, the socket fails to create.public void setAppendedFds(FileDescriptor[] fds) throws IOException
fds - Indicates an array of file descriptors.IOException - Throws this exception if an error occurs during the socket creation,
for example, the socket fails to create.