Code example for Socket

Methods: getLocalAddress

    @Override public int getMtu(Socket socket) throws IOException {
      try { 
        NetworkInterface networkInterface = NetworkInterface.getByInetAddress(
        if (networkInterface == null) {
          return super.getMtu(socket); // There's no longer an interface with this local address.
        return (Integer) getMtu.invoke(networkInterface);
      } catch (NullPointerException e) {
        // Certain Alcatel devices throw on getByInetAddress. Return default. 
        return super.getMtu(socket);
      } catch (SocketException e) {
        // Certain Motorola devices always throw on getByInetAddress. Return the default for those. 
        return super.getMtu(socket);
      } catch (IllegalAccessException e) {
        throw new AssertionError(e);
      } catch (InvocationTargetException e) {
        if (e.getCause() instanceof IOException) throw (IOException) e.getCause();
        throw new RuntimeException(e.getCause());