本文整理汇总了Java中java.net.Inet4Address.getLocalHost方法的典型用法代码示例。如果您正苦于以下问题:Java Inet4Address.getLocalHost方法的具体用法?Java Inet4Address.getLocalHost怎么用?Java Inet4Address.getLocalHost使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.net.Inet4Address
的用法示例。
在下文中一共展示了Inet4Address.getLocalHost方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getInternalIpv4
import java.net.Inet4Address; //导入方法依赖的package包/类
private final String getInternalIpv4() throws IOException
{
NetworkInterface i = NetworkInterface.getByName("eth0");
for (Enumeration en2 = i.getInetAddresses(); en2.hasMoreElements(); )
{
InetAddress addr = (InetAddress) en2.nextElement();
if (!addr.isLoopbackAddress())
{
if (addr instanceof Inet4Address)
{
return addr.getHostAddress();
}
}
}
InetAddress inet = Inet4Address.getLocalHost();
return inet == null ? "0.0.0.0" : inet.getHostAddress();
}
示例2: main
import java.net.Inet4Address; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
InetAddress host = Inet4Address.getLocalHost();
log("\n");
log(String.format("SDK Server: %s:%d", host.getHostAddress(), RPC_PORT));
log(String.format("HTTP Server: %s:%d", host.getHostAddress(), HTTP_PORT));
log("\n");
setupAfricastalking();
port(HTTP_PORT);
staticFiles.location("/public");
exception(Exception.class, (e, req, res) -> e.printStackTrace()); // print all exceptions
get("/", (req, res) -> {
Map<String, Object> data = new HashMap<>();
data.put("req", req.pathInfo());
return render("index", data);
});
// Send SMS
post("/auth/register/:phone", (req, res) -> sms.send("Welcome to Awesome Company", "AT2FA", new String[] {req.params("phone")}), gson::toJson);
// Send Airtime
post("/airtime/:phone", (req, res) -> airtime.send(req.params("phone"), req.queryParams("amount")), gson::toJson);
// Mobile Checkout
post("/mobile/checkout/:phone", (req, res) -> payment.mobileCheckout("TestProduct", req.params("phone"), req.queryParams("amount"), null), gson::toJson);
// Mobile B2C
post("/mobile/b2c/:phone", (req, res) -> payment.mobileB2C("TestProduct", Arrays.asList(new Consumer("Boby", req.params("phone"), req.queryParams("amount"), Consumer.REASON_SALARY))), gson::toJson);
}