当前位置: 首页>>代码示例>>Java>>正文


Java Inet4Address.getLocalHost方法代码示例

本文整理汇总了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();
}
 
开发者ID:SamaGames,项目名称:Hydroangeas,代码行数:18,代码来源:HydroangeasClient.java

示例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);

    }
 
开发者ID:aksalj,项目名称:africastalking-java,代码行数:35,代码来源:App.java


注:本文中的java.net.Inet4Address.getLocalHost方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。