Class UdpMessenger

java.lang.Object
java.lang.Thread
org.sentrysoftware.ipmi.core.transport.UdpMessenger
All Implemented Interfaces:
Runnable, Messenger

public class UdpMessenger extends Thread implements Messenger
Handles the UDP connection.
  • Constructor Details

    • UdpMessenger

      public UdpMessenger(int port) throws SocketException, UnknownHostException
      Initiates UdpMessenger, binds it to the specified port and starts listening. Wildcard IP address will be used.
      Parameters:
      port - - port to bind socket to.
      Throws:
      SocketException - if the socket could not be opened, or the socket could not bind to the specified local port.
      UnknownHostException
    • UdpMessenger

      public UdpMessenger(int port, InetAddress address) throws SocketException
      Initiates UdpMessenger, binds it to the specified port and IP address and starts listening.
      Parameters:
      port - - port to bind socket to.
      address - - IP address to bind socket to.
      Throws:
      SocketException - if the socket could not be opened, or the socket could not bind to the specified local port.
  • Method Details

    • getPort

      public int getPort()
    • setBufferSize

      public void setBufferSize(int bufferSize)
      Sets message data buffer size to bufferSize.
    • getBufferSize

      public int getBufferSize()
      Returns:
      Size of the message data buffer
    • run

      public void run()
      Specified by:
      run in interface Runnable
      Overrides:
      run in class Thread
    • closeConnection

      public void closeConnection()
      Closes the socket and releases port.
      Specified by:
      closeConnection in interface Messenger
    • register

      public void register(UdpListener listener)
      Registers listener in the UdpMessenger so it will be notified via UdpListener.notifyMessage(UdpMessage) when new message arrives.
      Specified by:
      register in interface Messenger
      Parameters:
      listener - - UdpListener to register.
    • unregister

      public void unregister(UdpListener listener)
      Unregisters listener from UdpMessenger so it no longer will be notified.
      Specified by:
      unregister in interface Messenger
      Parameters:
      listener - - UdpListener to unregister
    • getSentPackets

      public static int getSentPackets()
      Returns number of packets sent since last creation of the instance of UdpMessenger. For debug/testing purposes only.
    • send

      public void send(UdpMessage message) throws IOException
      Sends UdpMessage.
      Specified by:
      send in interface Messenger
      Parameters:
      message - - UdpMessage to send.
      Throws:
      IOException - when sending of the message fails