當前位置: 首頁>>代碼示例>>Java>>正文


Java NetworkInterface.getMTU方法代碼示例

本文整理匯總了Java中java.net.NetworkInterface.getMTU方法的典型用法代碼示例。如果您正苦於以下問題:Java NetworkInterface.getMTU方法的具體用法?Java NetworkInterface.getMTU怎麽用?Java NetworkInterface.getMTU使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.net.NetworkInterface的用法示例。


在下文中一共展示了NetworkInterface.getMTU方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getMSS

import java.net.NetworkInterface; //導入方法依賴的package包/類
private int getMSS(SocketChannel sc) {

        int retMSS = Config.NETWORK_BUFF_LEN_SIZE;

        try {
            final InetAddress ia = sc.socket().getLocalAddress();
            NetworkInterface ni = NetworkInterface.getByInetAddress(ia);
            int mss = ni.getMTU() - 40;
            if (mss > 1000) {
                retMSS = mss;
            }
        } catch (Throwable t) {
            if (logger.isLoggable(Level.FINE)) {
                logger.log(Level.FINE, "Cannot determine MTU for socket channel: " + sc);
            }
        }

        return retMSS;
    }
 
開發者ID:fast-data-transfer,項目名稱:fdt,代碼行數:20,代碼來源:TCPSessionWriter.java

示例2: getMaximumTransferUnit

import java.net.NetworkInterface; //導入方法依賴的package包/類
/**
 * @return the maximum transfer unit of the network interface binded to the
 * localhost.
 */
public static int getMaximumTransferUnit() {
    try {
        return NetworkInterface.getByInetAddress(InetAddress.getLocalHost()).getMTU();
    } catch (Throwable throwable) {
        try {
            /*
 * We failed to get the NetworkInterface, we're gonna have to
 * cycle through them manually and choose the lowest one to make
 * sure we never exceed any hardware limitations
 */
            boolean foundDevice = false;
            int lowestMaximumTransferUnit = Integer.MAX_VALUE;
            for (Enumeration<NetworkInterface> networkInterfaces = NetworkInterface
                    .getNetworkInterfaces(); networkInterfaces.hasMoreElements(); ) {
                NetworkInterface networkInterface = networkInterfaces.nextElement();
                int maximumTransferUnit = networkInterface.getMTU();
                if (maximumTransferUnit < lowestMaximumTransferUnit
                        && maximumTransferUnit >= RakNet.MINIMUM_TRANSFER_UNIT) {
                    lowestMaximumTransferUnit = maximumTransferUnit;
                    foundDevice = true;
                }
            }

            // This is a serious error and will cause startup to fail
            if (foundDevice == false) {
                throw new IOException("Failed to locate a network interface with an MTU higher than the minimum ("
                        + RakNet.MINIMUM_TRANSFER_UNIT + ")");
            }
            return lowestMaximumTransferUnit;
        } catch (Throwable throwable2) {
            throwable2.printStackTrace();
            return -1;
        }
    }
}
 
開發者ID:KernelFreeze,項目名稱:BedrockProxy,代碼行數:40,代碼來源:RakNetUtils.java


注:本文中的java.net.NetworkInterface.getMTU方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。