use of java.net.Inet4Address in project cw-omnibus by commonsguy.
the class WebServerService method raiseReadyEvent.
private void raiseReadyEvent() {
ServerStartedEvent event = new ServerStartedEvent();
try {
for (Enumeration<NetworkInterface> enInterfaces = NetworkInterface.getNetworkInterfaces(); enInterfaces.hasMoreElements(); ) {
NetworkInterface ni = enInterfaces.nextElement();
for (Enumeration<InetAddress> enAddresses = ni.getInetAddresses(); enAddresses.hasMoreElements(); ) {
InetAddress addr = enAddresses.nextElement();
if (addr instanceof Inet4Address) {
event.addUrl("http://" + addr.getHostAddress() + ":4999" + rootPath + "/");
}
}
}
} catch (SocketException ex) {
ex.printStackTrace();
}
EventBus.getDefault().removeAllStickyEvents();
EventBus.getDefault().postSticky(event);
}
use of java.net.Inet4Address in project cw-omnibus by commonsguy.
the class WebServerService method raiseReadyEvent.
private void raiseReadyEvent() {
ServerStartedEvent event = new ServerStartedEvent();
try {
for (Enumeration<NetworkInterface> enInterfaces = NetworkInterface.getNetworkInterfaces(); enInterfaces.hasMoreElements(); ) {
NetworkInterface ni = enInterfaces.nextElement();
for (Enumeration<InetAddress> enAddresses = ni.getInetAddresses(); enAddresses.hasMoreElements(); ) {
InetAddress addr = enAddresses.nextElement();
if (addr instanceof Inet4Address) {
event.addUrl("http://" + addr.getHostAddress() + ":4999" + rootPath + "/");
}
}
}
} catch (SocketException ex) {
ex.printStackTrace();
}
EventBus.getDefault().removeAllStickyEvents();
EventBus.getDefault().postSticky(event);
}
use of java.net.Inet4Address in project cw-omnibus by commonsguy.
the class WebServerService method raiseStartedEvent.
private void raiseStartedEvent() {
ServerStartedEvent event = new ServerStartedEvent();
try {
for (Enumeration<NetworkInterface> enInterfaces = NetworkInterface.getNetworkInterfaces(); enInterfaces.hasMoreElements(); ) {
NetworkInterface ni = enInterfaces.nextElement();
for (Enumeration<InetAddress> enAddresses = ni.getInetAddresses(); enAddresses.hasMoreElements(); ) {
InetAddress addr = enAddresses.nextElement();
if (addr instanceof Inet4Address) {
event.addUrl("http://" + addr.getHostAddress() + ":4999");
}
}
}
} catch (SocketException e) {
Log.e(getClass().getSimpleName(), "Exception in IP addresses", e);
}
EventBus.getDefault().removeAllStickyEvents();
EventBus.getDefault().postSticky(event);
}
use of java.net.Inet4Address in project crate by crate.
the class PostgresNetty method resolveBindAddress.
private BoundTransportAddress resolveBindAddress() {
// Bind and start to accept incoming connections.
try {
InetAddress[] hostAddresses = networkService.resolveBindHostAddresses(null);
for (InetAddress address : hostAddresses) {
if (address instanceof Inet4Address) {
boundAddresses.add(bindAddress(address));
}
}
} catch (IOException e) {
throw new BindPostgresException("Failed to resolve binding network host", e);
}
final InetAddress publishInetAddress;
try {
publishInetAddress = networkService.resolvePublishHostAddresses(null);
} catch (Exception e) {
throw new BindTransportException("Failed to resolve publish address", e);
}
final int publishPort = resolvePublishPort(boundAddresses, publishInetAddress);
final InetSocketAddress publishAddress = new InetSocketAddress(publishInetAddress, publishPort);
return new BoundTransportAddress(boundAddresses.toArray(new TransportAddress[boundAddresses.size()]), new InetSocketTransportAddress(publishAddress));
}
use of java.net.Inet4Address in project che by eclipse.
the class DefaultNetworkFinderHelperTest method checkFoundIpForABridge.
/**
* Check that we can find ipv4 address if we have some bridge
*
* @throws SocketException
*/
@Test
public void checkFoundIpForABridge() throws SocketException {
DefaultNetworkFinder networkFinder = new DefaultNetworkFinder();
Enumeration<NetworkInterface> enumNetworkInterfaces = NetworkInterface.getNetworkInterfaces();
while (enumNetworkInterfaces.hasMoreElements()) {
NetworkInterface networkInterface = enumNetworkInterfaces.nextElement();
Optional<InetAddress> foundIpAddress = networkFinder.getIPAddress(networkInterface.getName());
Enumeration<InetAddress> enumAddresses = networkInterface.getInetAddresses();
List<InetAddress> list = new ArrayList<>();
while (enumAddresses.hasMoreElements()) {
InetAddress inetAddress = enumAddresses.nextElement();
if (inetAddress instanceof Inet4Address) {
list.add(inetAddress);
}
}
if (list.size() > 0) {
assertTrue(foundIpAddress.isPresent());
assertTrue(list.contains(foundIpAddress.get()));
}
}
}
Aggregations