public interface ClientSocketFactory
Modifier and Type | Method | Description |
---|---|---|
java.net.DatagramSocket |
createDatagramSocket() |
Creates a datagram socket for UDP communication.
|
java.net.Socket |
createSocket() |
Creates a TCP socket.
|
java.net.InetAddress |
getAddress() |
Returns the address being used to create sockets.
|
int |
getPort() |
Returns the port being used to create sockets.
|
default java.net.SocketAddress |
getSocketAddress() |
A convenience method to return the socket address.
|
static ClientSocketFactory |
of(java.net.InetAddress address,
int port) |
Creates a new default implementation of the factory which uses
SocketFactory.getDefault() for TCP
sockets and new DatagramSocket() for UDP sockets. |
static ClientSocketFactory |
of(javax.net.SocketFactory socketFactory,
java.net.InetAddress address,
int port) |
Creates a new default implementation of the factory which uses the provided
socket factory to create TCP connections and
new DatagramSocket() for UDP sockets. |
java.net.DatagramSocket createDatagramSocket() throws java.net.SocketException
java.net.SocketException
- if binding the socket failsjava.net.Socket createSocket() throws java.io.IOException
java.io.IOException
- if an error occurs creating the socketjava.net.InetAddress getAddress()
int getPort()
default java.net.SocketAddress getSocketAddress()
The default implementation simply returns new InetSocketAddress(getAddress(), getPort())
.
static ClientSocketFactory of(java.net.InetAddress address, int port)
SocketFactory.getDefault()
for TCP
sockets and new DatagramSocket()
for UDP sockets.address
- the address to bind toport
- the port to bind tostatic ClientSocketFactory of(javax.net.SocketFactory socketFactory, java.net.InetAddress address, int port)
new DatagramSocket()
for UDP sockets.socketFactory
- the socket factory used for TCP connections, if null
the
default socket factory will be usedaddress
- the address to bind toport
- the port to bind toCopyright © 2018. All rights reserved.