Package com.metratec.lib.connection
Class UdpConnection
- java.lang.Object
-
- com.metratec.lib.connection.UdpConnection
-
public abstract class UdpConnection extends java.lang.Object
A connection to a udp port- Version:
- 1.22.4
- Author:
- man
-
-
Constructor Summary
Constructors Constructor Description UdpConnection()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.util.List<java.net.InetAddress>
getAllInterfaceInetAddresses()
Get the InetAddresses of all local network interfaces.static java.util.List<EthernetDevice>
getLantronixEthernetDevices(int timeout)
Send UDP broadcasts on all local network interfaces and return all responding Lantronix devices.static java.util.List<EthernetDevice>
getLantronixEthernetDevices(int timeout, java.net.InetAddress addr)
Send UDP broadcast from a specific IP address and return all responding Lantronix devices.static java.util.List<EthernetDevice>
getLantronixEthernetDevices(int timeout, java.util.List<java.net.InetAddress> addresses)
Send UDP broadcasts from a specified list of IP addresses and return all responding Lantronix devices.static java.util.List<EthernetDevice>
getMetratecEthernetDevices(int udpTimeout)
Send UDP broadcasts on all local network interfaces and return all responding metraTec TUC devices.static java.util.List<EthernetDevice>
getMetratecEthernetDevices(int timeout, java.net.InetAddress addr)
Send UDP and UPNP broadcast from a specific IP address and return all responding metraTec TUC devices.static java.util.List<EthernetDevice>
getMetratecEthernetDevices(int timeout, java.util.List<java.net.InetAddress> addresses)
Send UDP from a specified list of IP addresses and return all responding metraTec TUC devices.static java.util.List<EthernetDevice>
getMetratecEthernetDevicesUdp(int timeout)
Send Upd broadcasts on all local network interfaces and return all responding metraTec TUC devices.static void
sendBroadcastRecvOnUnicast(java.net.DatagramPacket sendPacket, int srcPort, int recvLength, int timeout, java.util.List<java.net.InetAddress> addresses, UdpBroadcastHandlerInterface handler)
Send broadcast packets from a list of source addresses and receive answers on the corresponding unicast addresses.static void
sendRecvBroadcast(java.net.DatagramPacket sendPacket, int srcPort, int recvLength, int timeout, UdpBroadcastHandlerInterface handler)
Send broadcast packets from all local interface addresses and receive broadcast answers in a platform-independant manner.static void
sendRecvBroadcast(java.net.DatagramPacket sendPacket, int srcPort, int recvLength, int timeout, java.net.InetAddress addr, UdpBroadcastHandlerInterface handler)
Send broadcast packets from a single source source address and receive broadcast answers in a platform-independant manner.static void
sendRecvBroadcast(java.net.DatagramPacket sendPacket, int srcPort, int recvLength, int timeout, java.util.List<java.net.InetAddress> addresses, UdpBroadcastHandlerInterface handler)
Send broadcast packets from a list of source addresses and receive broadcast answers in a platform-independant manner.
-
-
-
Method Detail
-
getAllInterfaceInetAddresses
public static java.util.List<java.net.InetAddress> getAllInterfaceInetAddresses() throws java.net.SocketException
Get the InetAddresses of all local network interfaces. Includes only IPv4 addresses and only real interface addresses (no local hosts etc.). It is important to keep this list as small as possible since it is also the list we send broadcasts on.- Returns:
- List of addresses
- Throws:
java.net.SocketException
- if an I/O error occurs.
-
sendBroadcastRecvOnUnicast
public static void sendBroadcastRecvOnUnicast(java.net.DatagramPacket sendPacket, int srcPort, int recvLength, int timeout, java.util.List<java.net.InetAddress> addresses, UdpBroadcastHandlerInterface handler) throws java.io.IOException
Send broadcast packets from a list of source addresses and receive answers on the corresponding unicast addresses.This can be used whenever a device responds to a broadcast packet with an unicast answer.
It can and must also be used on Windows to receive broadcast answers. However you should not use this method in portable code that needs to receive broadcast answers since different operating systems need different tricks to receive broadcast responses and associate them with specific local interfaces. Always use
sendRecvBroadcast(DatagramPacket, int, int, int, List, UdpBroadcastHandlerInterface)
for that purpose.- Parameters:
sendPacket
- Packet to broadcast. The destination address is set to 255.255.255.255 automatically. If this is null, no packet is sent.srcPort
- Source port of outbound broadcasts and used to listen for responses.recvLength
- Length of response packets. This will be the length of returned packets' data buffers. If less than or equal 0, do not try to receive any packets.timeout
- Time to wait for responses in milliseconds.addresses
- Addresses to bind to when broadcasting. This effectively determines the interfaces that sendPacket will be broadcast on.handler
- A functor object for handling received responses/packets.- Throws:
java.io.IOException
- if an unexpected I/O error occured.
-
sendRecvBroadcast
public static void sendRecvBroadcast(java.net.DatagramPacket sendPacket, int srcPort, int recvLength, int timeout, UdpBroadcastHandlerInterface handler) throws java.io.IOException
Send broadcast packets from all local interface addresses and receive broadcast answers in a platform-independant manner.- Parameters:
sendPacket
- Packet to broadcast. The destination address is set to 255.255.255.255 automatically. If this is null, no packet is sent.srcPort
- Source port of outbound broadcasts and used for listening for broadcasts.recvLength
- Length of broadcast responses. This will be the length of returned packets' data buffers. If less than or equal 0, do not try to receive any packets.timeout
- Time to wait for responses in milliseconds.handler
- A functor object for handling received broadcast responses/packets.- Throws:
java.io.IOException
- if an unexpected I/O error occured.
-
sendRecvBroadcast
public static void sendRecvBroadcast(java.net.DatagramPacket sendPacket, int srcPort, int recvLength, int timeout, java.net.InetAddress addr, UdpBroadcastHandlerInterface handler) throws java.io.IOException
Send broadcast packets from a single source source address and receive broadcast answers in a platform-independant manner.- Parameters:
sendPacket
- Packet to broadcast. The destination address is set to 255.255.255.255 automatically. If this is null, no packet is sent.srcPort
- Source port of outbound broadcasts and used for listening for broadcasts.recvLength
- Length of broadcast responses. This will be the length of returned packets' data buffers. If less than or equal 0, do not try to receive any packets.timeout
- Time to wait for responses in milliseconds.addr
- Address to bind to when broadcasting. This effectively determines the interface that sendPacket will be broadcast on.handler
- A functor object for handling received broadcast responses/packets.- Throws:
java.io.IOException
- if an unexpected I/O error occured.
-
sendRecvBroadcast
public static void sendRecvBroadcast(java.net.DatagramPacket sendPacket, int srcPort, int recvLength, int timeout, java.util.List<java.net.InetAddress> addresses, UdpBroadcastHandlerInterface handler) throws java.io.IOException
Send broadcast packets from a list of source addresses and receive broadcast answers in a platform-independant manner.- Parameters:
sendPacket
- Packet to broadcast. The destination address is set to 255.255.255.255 automatically. If this is null, no packet is sent.srcPort
- Source port of outbound broadcasts and used for listening for broadcasts.recvLength
- Length of broadcast responses. This will be the length of returned packets' data buffers. If less than or equal 0, do not try to receive any packets.timeout
- Time to wait for responses in milliseconds.addresses
- Addresses to bind to when broadcasting. This effectively determines the interfaces that sendPacket will be broadcast on.handler
- A functor object for handling received broadcast responses/packets.- Throws:
java.io.IOException
- if an unexpected I/O error occured.
-
getLantronixEthernetDevices
public static java.util.List<EthernetDevice> getLantronixEthernetDevices(int timeout) throws java.io.IOException
Send UDP broadcasts on all local network interfaces and return all responding Lantronix devices.- Parameters:
timeout
- Time to wait for responses in milliseconds.- Returns:
- List of Lantronix devices. It is already sorted.
- Throws:
java.io.IOException
- if an unexpected I/O error occurs.
-
getLantronixEthernetDevices
public static java.util.List<EthernetDevice> getLantronixEthernetDevices(int timeout, java.net.InetAddress addr) throws java.io.IOException
Send UDP broadcast from a specific IP address and return all responding Lantronix devices.- Parameters:
timeout
- Time to wait for responses in milliseconds.addr
- Address to bind to, i.e. address of the interface to send broadcast on.- Returns:
- List of Lantronix devices. It is already sorted.
- Throws:
java.io.IOException
- if an unexpected I/O error occurs.
-
getLantronixEthernetDevices
public static java.util.List<EthernetDevice> getLantronixEthernetDevices(int timeout, java.util.List<java.net.InetAddress> addresses) throws java.io.IOException
Send UDP broadcasts from a specified list of IP addresses and return all responding Lantronix devices.- Parameters:
timeout
- Time to wait for responses in milliseconds.addresses
- Addresses to bind to when broadcasting. This effectively determines the interfaces that sendPacket will be broadcast on.- Returns:
- List of Lantronix devices. It is already sorted.
- Throws:
java.io.IOException
- if an unexpected I/O error occurs.
-
getMetratecEthernetDevices
public static java.util.List<EthernetDevice> getMetratecEthernetDevices(int udpTimeout) throws java.io.IOException
Send UDP broadcasts on all local network interfaces and return all responding metraTec TUC devices.- Parameters:
udpTimeout
- Time to wait for responses in milliseconds.- Returns:
- List of TUC devices. It is sorted already.
- Throws:
java.io.IOException
- if an unexpected I/O error occurs.
-
getMetratecEthernetDevices
public static java.util.List<EthernetDevice> getMetratecEthernetDevices(int timeout, java.net.InetAddress addr) throws java.io.IOException
Send UDP and UPNP broadcast from a specific IP address and return all responding metraTec TUC devices.- Parameters:
timeout
- Time to wait for udp and upnp responses in milliseconds.addr
- Address to bind to, i.e. address of the interface to send broadcast on.- Returns:
- List of TUC devices. It is sorted already.
- Throws:
java.io.IOException
- if an unexpected I/O error occurs.
-
getMetratecEthernetDevicesUdp
public static java.util.List<EthernetDevice> getMetratecEthernetDevicesUdp(int timeout) throws java.io.IOException
Send Upd broadcasts on all local network interfaces and return all responding metraTec TUC devices.- Parameters:
timeout
- Time to wait for responses in milliseconds.- Returns:
- List of TUC devices. It is sorted already.
- Throws:
java.io.IOException
- if an unexpected I/O error occurs.
-
getMetratecEthernetDevices
public static java.util.List<EthernetDevice> getMetratecEthernetDevices(int timeout, java.util.List<java.net.InetAddress> addresses) throws java.io.IOException
Send UDP from a specified list of IP addresses and return all responding metraTec TUC devices.- Parameters:
timeout
- Time to wait for udp and upnp responses in milliseconds.addresses
- Addresses to bind to when broadcasting. This effectively determines the interfaces that sendPacket will be broadcast on.- Returns:
- List of TUC devices. It is sorted already.
- Throws:
java.io.IOException
- if an unexpected I/O error occurs.
-
-