/** Return the hostname of the local machine. */ public static String getLocalAddress() { String address = null; try { InetAddress ia = InetAddress.getLocalHost(); address = ia.getHostAddress(); } catch (UnknownHostException e) { return "127.0.0.1"; } return address; }
/** Return the hostname of the local machine. */ public static String getLocalHost() { String hostname = null; try { InetAddress ia = InetAddress.getLocalHost(); hostname = ia.getHostName(); } catch (UnknownHostException e) { return "localhost"; } return hostname; }
private void setMailCredential(CIJob job) { if (debugEnabled) { S_LOGGER.debug("Entering Method CIManagerImpl.setMailCredential"); } try { String jenkinsTemplateDir = Utility.getJenkinsTemplateDir(); String mailFilePath = jenkinsTemplateDir + MAIL + HYPHEN + CREDENTIAL_XML; if (debugEnabled) { S_LOGGER.debug("configFilePath ... " + mailFilePath); } File mailFile = new File(mailFilePath); SvnProcessor processor = new SvnProcessor(mailFile); // DataInputStream in = new DataInputStream(new FileInputStream(mailFile)); // while (in.available() != 0) { // System.out.println(in.readLine()); // } // in.close(); // Mail have to go with jenkins running email address InetAddress ownIP = InetAddress.getLocalHost(); processor.changeNodeValue( CI_HUDSONURL, HTTP_PROTOCOL + PROTOCOL_POSTFIX + ownIP.getHostAddress() + COLON + job.getJenkinsPort() + FORWARD_SLASH + CI + FORWARD_SLASH); processor.changeNodeValue("smtpAuthUsername", job.getSenderEmailId()); processor.changeNodeValue("smtpAuthPassword", job.getSenderEmailPassword()); processor.changeNodeValue("adminAddress", job.getSenderEmailId()); // jenkins home location String jenkinsJobHome = System.getenv(JENKINS_HOME); StringBuilder builder = new StringBuilder(jenkinsJobHome); builder.append(File.separator); processor.writeStream(new File(builder.toString() + CI_MAILER_XML)); } catch (Exception e) { S_LOGGER.error( "Entered into the catch block of CIManagerImpl.setMailCredential " + e.getLocalizedMessage()); } }
public static String ip() { try { return InetAddress.getLocalHost().getHostAddress(); } catch (UnknownHostException e) { e.printStackTrace(); return null; } }
/** * @param parent typically use "this" * @param port port used to transfer data * @param host when multiple NICs are in use, the ip (or name) to bind from */ public MyServer(PApplet parent, int port, String host) { this.parent = parent; this.port = port; try { if (host == null) { server = new ServerSocket(this.port); } else { server = new ServerSocket(this.port, 10, InetAddress.getByName(host)); } // clients = new Vector(); clients = new Client[10]; thread = new Thread(this); thread.start(); parent.registerMethod("dispose", this); // reflection to check whether host applet has a call for // public void serverEvent(MyServer s, Client c); // which is called when a new guy connects try { serverEventMethod = parent.getClass().getMethod("serverEvent", new Class[] {MyServer.class, Client.class}); } catch (Exception e) { // no such method, or an error.. which is fine, just ignore serverEventMethod = null; } try { clientValidationMethod = parent .getClass() .getMethod("clientValidation", new Class[] {MyServer.class, Client.class}); } catch (Exception e) { // no such method, or an error.. which is fine, just ignore clientValidationMethod = null; } } catch (IOException e) { // e.printStackTrace(); thread = null; throw new RuntimeException(e); // errorMessage("<init>", e); } }
private void init() throws IOException { messageBuffer = new ArrayList(); receiveBuffer = ByteBuffer.allocate(CAPACITY); sendBuffer = ByteBuffer.allocate(CAPACITY); buf = new byte[CAPACITY]; channel = DatagramChannel.open(); channel.configureBlocking(false); InetAddress host = null; if (getAddress() != null) { host = InetAddress.getByAddress(getAddress().getBytes()); } channel.socket().bind(new InetSocketAddress(host, getPort())); channel.socket().setReceiveBufferSize(CAPACITY); certifier = new MessageCertifier(this); extractor = new MessageExtractor(this); }