public class NetMarshalServer
extends java.lang.Object
implements java.io.Closeable
NetMarshalClient
s.
NOTE: Methods that are synchronised are used here, do NOT use instances of these classes as monitors.Constructor and Description |
---|
NetMarshalServer(java.net.DatagramSocket socketIn,
IPacketFactory factory,
PacketLoader loader,
FragmentationOptions fragmentationOptions)
Constructs a new NetMarshalServer with the specified
DatagramSocket , IPacketFactory , PacketLoader and FragmentationOptions . |
NetMarshalServer(java.net.ServerSocket socketIn,
IPacketFactory factory,
PacketLoader loader,
FragmentationOptions fragmentationOptions)
Constructs a new NetMarshalServer with the specified
ServerSocket , IPacketFactory , PacketLoader and FragmentationOptions . |
Modifier and Type | Method and Description |
---|---|
void |
broadcastPacket(IPacket packetIn,
boolean directSend)
Broadcasts a
IPacket . |
void |
close()
Closes the marshal, closing all the connected clients.
|
NetMarshalClient |
connect(java.net.InetAddress remoteAddress,
int remotePort,
int timeout)
Connects to a remote endpoint.
|
void |
disconnectAll()
Disconnects all the clients (By closing them).
|
void |
flush()
Flushes all the output streams on all the clients.
|
java.util.function.BiConsumer<java.lang.Exception,NetMarshalServer> |
getAcceptExceptionBiConsumer()
Gets the
BiConsumer accept exception consumer. |
java.util.function.BiConsumer<CandidateClient,NetMarshalServer> |
getClientAcceptanceBiConsumer()
Gets the
BiConsumer client acceptance consumer. |
java.util.function.Consumer<NetMarshalClient> |
getClosedConsumer()
Gets the
Consumer closed consumer. |
NetMarshalClient[] |
getConnectedClients()
Gets the current set of connected
NetMarshalClient s. |
FragmentationOptions |
getFragmentationOptions()
Gets the
FragmentationOptions of the client. |
java.util.function.Consumer<NetMarshalClient> |
getOpenedConsumer()
Gets the
Consumer opened consumer. |
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.util.function.BiConsumer<java.net.Socket,NetMarshalServer> |
getSocketSetupBiConsumer()
Gets the
BiConsumer socket setup consumer. |
boolean |
isRunning()
Gets if the marshal is running.
|
java.net.InetAddress |
localAddress()
Get the local
InetAddress . |
int |
localPort()
Get the local port.
|
void |
open()
Opens the marshal.
|
void |
setAcceptExceptionBiConsumer(java.util.function.BiConsumer<java.lang.Exception,NetMarshalServer> consumer)
Sets the
BiConsumer accept exception consumer. |
void |
setClientAcceptanceBiConsumer(java.util.function.BiConsumer<CandidateClient,NetMarshalServer> consumer)
Sets the
BiConsumer client acceptance consumer. |
void |
setClosedConsumer(java.util.function.Consumer<NetMarshalClient> consumer)
Sets the
Consumer closed consumer. |
void |
setOpenedConsumer(java.util.function.Consumer<NetMarshalClient> consumer)
Sets the
Consumer opened consumer. |
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 |
setSocketSetupBiConsumer(java.util.function.BiConsumer<java.net.Socket,NetMarshalServer> consumer)
Sets the
BiConsumer socket setup consumer. |
public NetMarshalServer(java.net.ServerSocket socketIn, IPacketFactory factory, PacketLoader loader, FragmentationOptions fragmentationOptions)
ServerSocket
, IPacketFactory
, PacketLoader
and FragmentationOptions
.socketIn
- The server 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 NetMarshalServer(java.net.DatagramSocket socketIn, IPacketFactory factory, PacketLoader loader, FragmentationOptions fragmentationOptions)
DatagramSocket
, IPacketFactory
, PacketLoader
and FragmentationOptions
.socketIn
- The datagram 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 final void open()
public IPacketFactory getPacketFactory()
public PacketLoader getPacketLoader()
public java.net.InetAddress localAddress()
InetAddress
.public int localPort()
public final boolean isRunning()
public FragmentationOptions getFragmentationOptions()
FragmentationOptions
of the client.public final NetMarshalClient[] getConnectedClients()
NetMarshalClient
s.public final void broadcastPacket(IPacket packetIn, boolean directSend) throws java.io.IOException, PacketException
IPacket
.packetIn
- The packet to broadcast.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 final void disconnectAll() throws java.io.IOException
java.io.IOException
- An I/O Exception has occurred.public java.util.function.BiConsumer<IPacket,NetMarshalClient> getReceiveBiConsumer()
BiConsumer
receiver consumer.
WARNING: Calling broadcastPacket(IPacket, boolean)
or flush()
could cause full buffer hangs.public void setReceiveBiConsumer(java.util.function.BiConsumer<IPacket,NetMarshalClient> consumer)
BiConsumer
receiver consumer.
WARNING: Calling broadcastPacket(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.BiConsumer<java.lang.Exception,NetMarshalServer> getAcceptExceptionBiConsumer()
BiConsumer
accept exception consumer.public void setAcceptExceptionBiConsumer(java.util.function.BiConsumer<java.lang.Exception,NetMarshalServer> consumer)
BiConsumer
accept 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 java.util.function.Consumer<NetMarshalClient> getOpenedConsumer()
Consumer
opened consumer.public void setOpenedConsumer(java.util.function.Consumer<NetMarshalClient> consumer)
Consumer
opened consumer.consumer
- The new opened consumer.java.lang.NullPointerException
- consumer is null.public java.util.function.BiConsumer<CandidateClient,NetMarshalServer> getClientAcceptanceBiConsumer()
BiConsumer
client acceptance consumer.
Use CandidateClient.accept
to declare whether the candidate should be accepted.public void setClientAcceptanceBiConsumer(java.util.function.BiConsumer<CandidateClient,NetMarshalServer> consumer)
BiConsumer
client acceptance consumer.
Use CandidateClient.accept
to declare whether the candidate should be accepted.consumer
- The new acceptance consumer.java.lang.NullPointerException
- consumer is null.public java.util.function.BiConsumer<java.net.Socket,NetMarshalServer> getSocketSetupBiConsumer()
BiConsumer
socket setup consumer.public void setSocketSetupBiConsumer(java.util.function.BiConsumer<java.net.Socket,NetMarshalServer> consumer)
BiConsumer
socket setup consumer.consumer
- The new setup consumer.java.lang.NullPointerException
- consumer is null.public final NetMarshalClient connect(java.net.InetAddress remoteAddress, int remotePort, int timeout) throws java.io.IOException
remoteAddress
- The remote address to connect to.remotePort
- The remote port to connect to.timeout
- The timeout of the connection attempt (0 for infinite timeout).java.io.IOException
- A connection error has occurred.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.