List of usage examples for java.net InetAddress getByName
public static InetAddress getByName(String host) throws UnknownHostException
From source file:at.tugraz.ist.akm.webservice.server.SimpleWebServer.java
public SimpleWebServer(Context context, WebserverProtocolConfig serverConfig, IHttpAccessCallback callback) throws Exception { mHttpAuthCallback = callback;/* www .j a va2 s .com*/ mContext = context; PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, this.getClass().getName()); WifiIpAddress wifiAddressReader = new WifiIpAddress(context); mSocketAddress = InetAddress.getByName(wifiAddressReader.readLocalIpAddress()); wifiAddressReader.close(); wifiAddressReader = null; setNewServerConfiguration(serverConfig); mLog.debug("building server for [" + mServerConfig.protocolName + "://" + mSocketAddress + ":" + mServerConfig.port + "]"); readRequestHandlers(); readRequestInterceptors(); }
From source file:com.netscape.cmsutil.util.Utils.java
public static void checkHost(String hostname) throws UnknownHostException { InetAddress.getByName(hostname); }
From source file:MulticastClient.java
public void run() { while (moreQuotes) { try { byte[] buf = new byte[256]; // construct quote String dString = null; if (in == null) dString = new Date().toString(); else dString = getNextQuote(); buf = dString.getBytes(); // send it InetAddress group = InetAddress.getByName("230.0.0.1"); DatagramPacket packet = new DatagramPacket(buf, buf.length, group, 4446); socket.send(packet);/*from www . jav a 2s.c o m*/ // sleep for a while try { sleep((long) (Math.random() * FIVE_SECONDS)); } catch (InterruptedException e) { } } catch (IOException e) { e.printStackTrace(); moreQuotes = false; } } socket.close(); }
From source file:org.doxu.g2.gwc.crawler.CrawlThread.java
private InetAddress getIPAddress(URI uri) { try {//from w w w . ja va2 s .co m InetAddress address = InetAddress.getByName(uri.getHost()); return address; } catch (UnknownHostException ex) { return null; } }
From source file:com.jcraft.weirdx.XDMCP.java
void getLocalHost(String name) { myaddress = new byte[4]; try {/* w w w .j a v a 2 s . c om*/ InetAddress local; if (name != null && name.length() > 0) { local = InetAddress.getByName(name); } else { local = InetAddress.getLocalHost(); } byte[] b = local.getHostAddress().getBytes(); int bi = 0; for (int i = 0; i < 4; i++) { myaddress[i] = 0; while (bi < b.length && b[bi] != '.') { myaddress[i] = (byte) (myaddress[i] * 10 + (b[bi] - '0')); bi++; } if (b.length <= bi) break; bi++; } } catch (Exception e) { LOG.error(e); } }
From source file:edu.vt.middleware.gator.log4j.SocketServerTest.java
/** * Tests connecting to the socket server and sending a logging event that * should be written to configured appenders. * * @throws Exception On errors.// ww w. j a va2 s.c o m */ @Test public void testConnectAndLog() throws Exception { final Socket sock = new Socket(); try { final SocketAddress addr = new InetSocketAddress(InetAddress.getByName(server.getBindAddress()), server.getPort()); sock.connect(addr, SOCKET_CONNECT_TIMEOUT); // Allow the socket server time to build the hierarchy // before sending a test logging event Thread.sleep(2000); Assert.assertEquals(1, server.getLoggingEventHandlers().size()); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Sending test logging event."); } final LoggingEvent event = new LoggingEvent(TEST_CATEGORY, Logger.getLogger(TEST_CATEGORY), Level.DEBUG, TEST_MESSAGE, null); final ObjectOutputStream oos = new ObjectOutputStream(sock.getOutputStream()); oos.writeObject(event); oos.flush(); } finally { if (sock.isConnected()) { sock.close(); } } // Pause to allow time for logging events to be written Thread.sleep(2000); // Client socket close should trigger cleanup of server handler mapping Assert.assertEquals(0, server.getLoggingEventHandlers().size()); for (AppenderConfig appender : testProject.getAppenders()) { final String logFilePath = FileHelper.pathCat(CLIENT_ROOT_DIR, testProject.getName(), appender.getAppenderParam("file").getValue()); final String contents = readTextFile(logFilePath); Assert.assertTrue(contents.contains(TEST_MESSAGE)); } }
From source file:com.webobjects.monitor.application.HostsPage.java
public WOComponent addHostClicked() { String nullOrError = null;//from ww w . j a v a 2s .com if (newHostName != null && (newHostName.length() > 0) && (String_Extensions.isValidXMLString(newHostName))) { try { InetAddress anAddress = InetAddress.getByName(newHostName); handler().startWriting(); try { if (newHostName.equalsIgnoreCase("localhost") || newHostName.equals("127.0.0.1")) { // only allow this to happen if we have no other hosts! if (!((siteConfig().hostArray() != null) && (siteConfig().hostArray().count() == 0))) { // we're OK to add localhost. nullOrError = "Hosts named localhost or 127.0.0.1 may not be added while other hosts are configured."; } } else { // this is for non-localhost hosts // only allow this to happen if localhost/127.0.0.1 // doesn't already exist! if (siteConfig().localhostOrLoopbackHostExists()) { nullOrError = "Additional hosts may not be added while a host named localhost or 127.0.0.1 is configured."; } } if ((nullOrError == null) && (siteConfig().hostWithAddress(anAddress) == null)) { if (hostMeetsMinimumVersion(anAddress)) { MHost host = new MHost(siteConfig(), newHostName, hostTypeSelection.toUpperCase()); // To avoid overwriting hosts NSArray tempHostArray = new NSArray(siteConfig().hostArray()); siteConfig().addHost_M(host); handler().sendOverwriteToWotaskd(host); if (tempHostArray.count() != 0) { handler().sendAddHostToWotaskds(host, tempHostArray); } } else { mySession().addErrorIfAbsent("The wotaskd on " + newHostName + " is an older version, please upgrade before adding..."); } } else { if (nullOrError != null) { mySession().addErrorIfAbsent(nullOrError); } else { mySession().addErrorIfAbsent("The host " + newHostName + " has already been added"); } } } finally { handler().endWriting(); } } catch (UnknownHostException ex) { mySession().addErrorIfAbsent("ERROR: Cannot find IP address for hostname: " + newHostName); } } else { mySession().addErrorIfAbsent(newHostName + " is not a valid hostname"); } newHostName = null; return HostsPage.create(context()); }
From source file:de.saly.elasticsearch.importer.imap.IMAPImporterCl.java
public static void start(Map<String, Object> settings, boolean embeddedMode) throws Exception { Settings.Builder builder = Settings.settingsBuilder(); for (String key : settings.keySet()) { builder.put(key, String.valueOf(settings.get(key))); }/*from w ww. j a v a2 s. co m*/ if (embeddedMode) { try { FileUtils.forceDelete(new File("./data")); } catch (Exception e) { //ignore } builder.put("path.home", "."); builder.put("node.local", true); builder.put("http.cors.enabled", true); builder.put("http.cors.allow-origin", "*"); builder.put("cluster.name", "imap-embedded-" + System.currentTimeMillis()); node = new PluginAwareNode(builder.build(), (Collection) Lists.newArrayList(MapperAttachmentsPlugin.class)); node.start(); client = node.client(); } else { Settings eSettings = builder.build(); client = new TransportClient.Builder().settings(eSettings).build(); String[] hosts = eSettings.get("elasticsearch.hosts").split(","); for (int i = 0; i < hosts.length; i++) { String host = hosts[i]; String hostOnly = host.split(":")[0]; String portOnly = host.split(":")[1]; System.out.println("Adding " + hostOnly + ":" + portOnly); ((TransportClient) client).addTransportAddress(new InetSocketTransportAddress( InetAddress.getByName(hostOnly), Integer.parseInt(portOnly))); } } imap = new IMAPImporter(settings, client); imap.start(); }
From source file:com.eventsourcing.hlc.NTPServerTimeProvider.java
protected void setServers(String[] ntpServers) { servers = Arrays.asList(ntpServers).stream().map(server -> { try {/*w w w . j av a 2s. co m*/ return InetAddress.getByName(server); } catch (UnknownHostException e) { return null; } }).filter(address -> address != null).collect(Collectors.toList()); }