Class UdpConnector

java.lang.Object
com.jme3.network.kernel.udp.UdpConnector
All Implemented Interfaces:
Connector

public class UdpConnector extends Object implements Connector
A straight forward datagram socket-based UDP connector implementation.
Author:
Paul Speed
  • Constructor Summary

    Constructors
    Constructor
    Description
    UdpConnector(InetAddress remote, int remotePort)
    Creates a new UDP connection that send datagrams to the specified address and port.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    This always returns false since the simple DatagramSocket usage cannot be run in a non-blocking way.
    protected void
    Ensures the connector has not been closed.
    void
    Closes the connection.
    boolean
    Returns true if this connector is currently connected.
    Reads a chunk of data from the connection, blocking if there is no data available.
    void
    Writes a chunk of data to the connection from data.position() to data.limit().

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • UdpConnector

      public UdpConnector(InetAddress remote, int remotePort) throws IOException
      Creates a new UDP connection that send datagrams to the specified address and port.
      Parameters:
      remote - the remote address
      remotePort - the remote port
      Throws:
      IOException - if the socket cannot be opened
  • Method Details

    • checkClosed

      protected void checkClosed()
      Ensures the connector has not been closed.
    • isConnected

      public boolean isConnected()
      Description copied from interface: Connector
      Returns true if this connector is currently connected.
      Specified by:
      isConnected in interface Connector
      Returns:
      true if the connector is connected
    • close

      public void close()
      Description copied from interface: Connector
      Closes the connection. Any subsequent attempts to read or write will fail with an exception.
      Specified by:
      close in interface Connector
    • available

      public boolean available()
      This always returns false since the simple DatagramSocket usage cannot be run in a non-blocking way.
      Specified by:
      available in interface Connector
      Returns:
      true if data may be available to read without blocking
    • read

      public ByteBuffer read()
      Description copied from interface: Connector
      Reads a chunk of data from the connection, blocking if there is no data available. The buffer may only be valid until the next read() call is made. Callers should copy the data if they need it for longer than that.
      Specified by:
      read in interface Connector
      Returns:
      The data read or null if there is no more data because the connection is closed.
    • write

      public void write(ByteBuffer data)
      Description copied from interface: Connector
      Writes a chunk of data to the connection from data.position() to data.limit().
      Specified by:
      write in interface Connector
      Parameters:
      data - the bytes to write