public class NetMarshalClient
extends java.lang.Object
implements java.io.Closeable
Constructor and Description |
---|
NetMarshalClient(java.net.DatagramSocket socketIn,
java.net.InetAddress remoteAddress,
int remotePort,
java.io.InputStream inputStream,
IPacketFactory factory,
PacketLoader loader,
FragmentationOptions fragmentationOptions)
Constructs a new NetMarshalClient with the specified
DatagramSocket , remote InetAddress , remote port, InputStream , IPacketFactory , PacketLoader and FragmentationOptions . |
NetMarshalClient(java.net.DatagramSocket socketIn,
java.net.InetAddress remoteAddress,
int remotePort,
IPacketFactory factory,
PacketLoader loader,
FragmentationOptions fragmentationOptions)
Constructs a new NetMarshalClient with the specified
DatagramSocket , remote InetAddress , remote port, IPacketFactory , PacketLoader and FragmentationOptions . |
NetMarshalClient(java.net.MulticastSocket socketIn,
java.net.InetAddress multicastGroupAddress,
int multicastGroupPort,
IPacketFactory factory,
PacketLoader loader,
FragmentationOptions fragmentationOptions)
Constructs a new NetMarshalClient with the specified
MulticastSocket , multicast group InetAddress , multicast port, IPacketFactory , PacketLoader and FragmentationOptions . |
NetMarshalClient(java.net.Socket socketIn,
IPacketFactory factory,
PacketLoader loader,
FragmentationOptions fragmentationOptions)
Constructs a new NetMarshalClient with the specified
Socket , IPacketFactory , PacketLoader and FragmentationOptions . |
Modifier and Type | Method and Description |
---|---|
boolean |
arePacketsBeingRead()
Are
IPacket s being read. |
boolean |
areReceivedPacketsWaiting()
Gets if there are received
IPacket s. |
void |
clearFragmentStorage()
Clears the fragment storage registries if fragmentation is enabled.
|
void |
close()
Closes the marshal, closing all its streams.
|
void |
flush()
Flushes the output streams.
|
java.util.function.Consumer<NetMarshalClient> |
getClosedConsumer()
Gets the
Consumer closed consumer. |
FragmentationOptions |
getFragmentationOptions()
Gets the
FragmentationOptions of the client. |
java.io.InputStream |
getInputStream()
Get the input stream.
|
java.io.OutputStream |
getOutputStream()
Get the output stream.
|
IPacketFactory |
getPacketFactory()
Gets the packet factory in use.
|
PacketLoader |
getPacketLoader()
Gets the packet loader in use.
|
java.util.function.BiConsumer<IPacket,NetMarshalClient> |
getReceiveBiConsumer()
Gets the
BiConsumer receiver consumer. |
java.util.function.BiConsumer<java.lang.Exception,NetMarshalClient> |
getReceiveExceptionBiConsumer()
Gets the
BiConsumer receive exception consumer. |
java.io.InputStream |
getRootInputStream()
Get the root input stream.
|
java.io.OutputStream |
getRootOutputStream()
Get the root output stream.
|
boolean |
isRunning()
Gets if the marshal is running.
|
boolean |
isSSLUpgraded()
Gets if the marshal is ssl upgraded.
|
java.net.InetAddress |
localAddress()
Get the local
InetAddress . |
int |
localPort()
Get the local port.
|
void |
open()
Opens the marshal.
|
IPacket |
receivePacket()
Receives a
IPacket . |
IPacket |
receivePacketPolled()
Receives a
IPacket polled. |
java.net.InetAddress |
remoteAddress()
Get the remote
InetAddress . |
int |
remotePort()
Get the remote port.
|
void |
sendPacket(IPacket packetIn,
boolean directSend)
Sends a
IPacket . |
void |
setClosedConsumer(java.util.function.Consumer<NetMarshalClient> consumer)
Sets the
Consumer closed consumer. |
void |
setPacketsShouldBeRead(boolean shouldRead)
Set if
IPacket s should be read. |
void |
setReceiveBiConsumer(java.util.function.BiConsumer<IPacket,NetMarshalClient> consumer)
Sets the
BiConsumer receiver consumer. |
void |
setReceiveExceptionBiConsumer(java.util.function.BiConsumer<java.lang.Exception,NetMarshalClient> consumer)
Sets the
BiConsumer receive exception consumer. |
void |
sslUpgradeClientSide(javax.net.ssl.SSLContext context,
java.lang.String remoteHostName)
Performs SSL socket upgrades on client side (Use for constructed sockets).
|
void |
sslUpgradeServerSide(javax.net.ssl.SSLContext context)
Performs SSL socket upgrades on server side (Use for accepted sockets).
|
public NetMarshalClient(java.net.Socket socketIn, IPacketFactory factory, PacketLoader loader, FragmentationOptions fragmentationOptions)
Socket
, IPacketFactory
, PacketLoader
and FragmentationOptions
.socketIn
- The socket to use.factory
- The packet factory to use.loader
- The packet loader to use.fragmentationOptions
- The fragmentation options, null to disable fragmentation.java.lang.NullPointerException
- socketIn, factory or loader is null.java.lang.IllegalArgumentException
- Fragmentation options failed validation.public NetMarshalClient(java.net.MulticastSocket socketIn, java.net.InetAddress multicastGroupAddress, int multicastGroupPort, IPacketFactory factory, PacketLoader loader, FragmentationOptions fragmentationOptions) throws java.io.IOException
MulticastSocket
, multicast group InetAddress
, multicast port, IPacketFactory
, PacketLoader
and FragmentationOptions
.
The MulticastSocket
will join the multicast group.socketIn
- The multicast socket to use.multicastGroupAddress
- The multicast group address.multicastGroupPort
- The multicast group port.factory
- The packet factory to use.loader
- The packet loader to use.fragmentationOptions
- The fragmentation options, null to disable fragmentation.java.io.IOException
- There is an error joining or multicastGroupAddress is not a multicast address.java.lang.NullPointerException
- socketIn, multicastGroupAddress, factory or loader is null.java.lang.IllegalArgumentException
- multicastGroupPort is less than 0 or greater than 65535 or fragmentation options failed validation.public NetMarshalClient(java.net.DatagramSocket socketIn, java.net.InetAddress remoteAddress, int remotePort, java.io.InputStream inputStream, IPacketFactory factory, PacketLoader loader, FragmentationOptions fragmentationOptions)
DatagramSocket
, remote InetAddress
, remote port, InputStream
, IPacketFactory
, PacketLoader
and FragmentationOptions
.socketIn
- The datagram socket to use.remoteAddress
- The remote address to send data to.remotePort
- The remote port to send data to.inputStream
- The receiving input stream.factory
- The packet factory to use.loader
- The loader to use.fragmentationOptions
- The fragmentation options, null to disable fragmentation.java.lang.NullPointerException
- socketIn, remoteAddress, inputStream, factory or loader is null.java.lang.IllegalArgumentException
- remotePort is less than 0 or greater than 65535 or fragmentation options failed validation.public NetMarshalClient(java.net.DatagramSocket socketIn, java.net.InetAddress remoteAddress, int remotePort, IPacketFactory factory, PacketLoader loader, FragmentationOptions fragmentationOptions)
DatagramSocket
, remote InetAddress
, remote port, IPacketFactory
, PacketLoader
and FragmentationOptions
.socketIn
- The datagram socket to use.remoteAddress
- The remote address to send data to.remotePort
- The remote port to send data to.factory
- The packet factory to use.loader
- The loader to use.fragmentationOptions
- The fragmentation options, null to disable fragmentation.java.lang.NullPointerException
- socketIn, remoteAddress, factory or loader is null.java.lang.IllegalArgumentException
- remotePort is less than 0 or greater than 65535 or fragmentation options failed validation.public final void open()
public java.io.InputStream getInputStream()
public java.io.InputStream getRootInputStream()
public java.io.OutputStream getOutputStream()
public java.io.OutputStream getRootOutputStream()
public IPacketFactory getPacketFactory()
public PacketLoader getPacketLoader()
public final void clearFragmentStorage()
public java.net.InetAddress localAddress()
InetAddress
.public int localPort()
public java.net.InetAddress remoteAddress()
InetAddress
.public int remotePort()
public final boolean isRunning()
public FragmentationOptions getFragmentationOptions()
FragmentationOptions
of the client.public final boolean isSSLUpgraded()
public final void sendPacket(IPacket packetIn, boolean directSend) throws java.io.IOException, PacketException
IPacket
.packetIn
- The packet to send.directSend
- Whether the packet should be sent directly or through the fragmentation system.java.io.IOException
- A stream exception has occurred.PacketException
- An exception has occurred.java.lang.NullPointerException
- packetIn is null.public final void flush() throws java.io.IOException
java.io.IOException
- A stream exception has occurred.public boolean areReceivedPacketsWaiting()
IPacket
s.public IPacket receivePacket() throws java.lang.InterruptedException
IPacket
.java.lang.InterruptedException
- A thread interruption has occurred.public IPacket receivePacketPolled()
IPacket
polled.public boolean arePacketsBeingRead()
IPacket
s being read.public void setPacketsShouldBeRead(boolean shouldRead)
IPacket
s should be read.shouldRead
- Should packets be read.public void sslUpgradeServerSide(javax.net.ssl.SSLContext context) throws SSLUtilityException, java.io.IOException
setPacketsShouldBeRead(boolean)
is set to false or in a BiConsumer
consumer for setReceiveBiConsumer(BiConsumer)
.context
- The SSL context to use.SSLUtilityException
- An SSL Utility exception has occurred.java.io.IOException
- An I/O Exception has occurred.java.lang.NullPointerException
- context is null.java.lang.IllegalStateException
- sslUpgrade methods should be called in a BiConsumer (for setReceiveBiConsumer)
within the target NetMarshalClient or when reading packets (arePacketsBeingRead) is disabled on the NetMarshalClient.public void sslUpgradeClientSide(javax.net.ssl.SSLContext context, java.lang.String remoteHostName) throws SSLUtilityException, java.io.IOException
setPacketsShouldBeRead(boolean)
is set to false or in a BiConsumer
consumer for setReceiveBiConsumer(BiConsumer)
.context
- The SSL context to use.remoteHostName
- The hostname of the remote server.SSLUtilityException
- An SSL Utility exception has occurred.java.io.IOException
- An I/O Exception has occurred.java.lang.NullPointerException
- context or remoteHostName is null.java.lang.IllegalStateException
- sslUpgrade methods should be called in a BiConsumer (for setReceiveBiConsumer)
within the target NetMarshalClient or when reading packets (arePacketsBeingRead) is disabled on the NetMarshalClient.public java.util.function.BiConsumer<IPacket,NetMarshalClient> getReceiveBiConsumer()
BiConsumer
receiver consumer.
WARNING: Calling sendPacket(IPacket, boolean)
or flush()
could cause full buffer hangs.public void setReceiveBiConsumer(java.util.function.BiConsumer<IPacket,NetMarshalClient> consumer)
BiConsumer
receiver consumer.
WARNING: Calling sendPacket(IPacket, boolean)
or flush()
could cause full buffer hangs.consumer
- The new receiver consumer.java.lang.NullPointerException
- consumer is null.public java.util.function.BiConsumer<java.lang.Exception,NetMarshalClient> getReceiveExceptionBiConsumer()
BiConsumer
receive exception consumer.public void setReceiveExceptionBiConsumer(java.util.function.BiConsumer<java.lang.Exception,NetMarshalClient> consumer)
BiConsumer
receive exception consumer.consumer
- The new exception consumer.java.lang.NullPointerException
- consumer is null.public java.util.function.Consumer<NetMarshalClient> getClosedConsumer()
Consumer
closed consumer.public void setClosedConsumer(java.util.function.Consumer<NetMarshalClient> consumer)
Consumer
closed consumer.consumer
- The new closed consumer.java.lang.NullPointerException
- consumer is null.public final void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
java.io.IOException
- An I/O Exception has occurred.