Class UdpKernel
java.lang.Object
com.jme3.network.kernel.AbstractKernel
com.jme3.network.kernel.udp.UdpKernel
- All Implemented Interfaces:
Kernel
A Kernel implementation using UDP packets.
- Author:
- Paul Speed
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classHost thread that receives UDP packets for this kernel.protected classWrites queued UDP packets on behalf of endpoints. -
Field Summary
Fields inherited from interface Kernel
EVENTS_PENDING -
Constructor Summary
ConstructorsConstructorDescriptionUdpKernel(int port) Creates a UDP kernel bound to the specified port on the wildcard address.UdpKernel(InetAddress host, int port) Creates a UDP kernel for the specified host and port.UdpKernel(InetSocketAddress address) Creates a UDP kernel for the specified socket address. -
Method Summary
Modifier and TypeMethodDescriptionvoidbroadcast(Filter<? super Endpoint> filter, ByteBuffer data, boolean reliable, boolean copy) Dispatches the data to all endpoints managed by the kernel.protected voidCalled by the endpoints when they need to be closed.protected UdpKernel.HostThreadCreates the host thread implementation used by this kernel.protected voidenqueueWrite(Endpoint endpoint, DatagramPacket packet) Queues a datagram for asynchronous sending.protected EndpointgetEndpoint(SocketAddress address, boolean create) Returns the endpoint for the specified socket address, optionally creating it.voidInitializes the kernel and starts any internal processing.protected voidnewData(DatagramPacket packet) Queues newly received datagram data as an envelope.voidGracefully terminates the kernel and stops any internal daemon processing.Methods inherited from class AbstractKernel
addEnvelope, addEvent, hasEnvelopes, nextEndpointId, nextEvent, read, reportError, wakeupReader
-
Constructor Details
-
UdpKernel
Creates a UDP kernel for the specified host and port.- Parameters:
host- the local bind addressport- the local bind port
-
UdpKernel
Creates a UDP kernel bound to the specified port on the wildcard address.- Parameters:
port- the local bind port- Throws:
IOException- if the address cannot be prepared
-
UdpKernel
Creates a UDP kernel for the specified socket address.- Parameters:
address- the local socket address
-
-
Method Details
-
createHostThread
Creates the host thread implementation used by this kernel.- Returns:
- the host thread
-
initialize
public void initialize()Description copied from interface:KernelInitializes the kernel and starts any internal processing. -
terminate
Description copied from interface:KernelGracefully terminates the kernel and stops any internal daemon processing. This method will not return until all internal threads have been shut down.- Throws:
InterruptedException- if the calling thread is interrupted while waiting
-
broadcast
public void broadcast(Filter<? super Endpoint> filter, ByteBuffer data, boolean reliable, boolean copy) Dispatches the data to all endpoints managed by the kernel. 'routing' is currently ignored.- Parameters:
filter- the endpoint filter used to select recipientsdata- the payload to sendreliable- true to use reliable transport semanticscopy- true to copy the buffer before dispatching it
-
getEndpoint
Returns the endpoint for the specified socket address, optionally creating it.- Parameters:
address- the remote socket addresscreate- true to create the endpoint if missing- Returns:
- the existing or newly created endpoint
-
closeEndpoint
Called by the endpoints when they need to be closed.- Parameters:
p- the endpoint to close- Throws:
IOException- if cleanup fails
-
newData
Queues newly received datagram data as an envelope.- Parameters:
packet- the received packet
-
enqueueWrite
Queues a datagram for asynchronous sending.- Parameters:
endpoint- the source endpointpacket- the packet to send
-