java.net.SocketException.printStackTrace()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(7.5k)|赞(0)|评价(0)|浏览(155)

本文整理了Java中java.net.SocketException.printStackTrace()方法的一些代码示例,展示了SocketException.printStackTrace()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。SocketException.printStackTrace()方法的具体详情如下:
包路径:java.net.SocketException
类名称:SocketException
方法名:printStackTrace

SocketException.printStackTrace介绍

暂无

代码示例

代码示例来源:origin: wildfly/wildfly

public static Collection<InetAddress> getAllAvailableAddresses() {
  Set<InetAddress> retval=new HashSet<>();
  Enumeration en;
  try {
    en=NetworkInterface.getNetworkInterfaces();
    if(en == null)
      return retval;
    while(en.hasMoreElements()) {
      NetworkInterface intf=(NetworkInterface)en.nextElement();
      Enumeration<InetAddress> addrs=intf.getInetAddresses();
      while(addrs.hasMoreElements())
        retval.add(addrs.nextElement());
    }
  }
  catch(SocketException e) {
    e.printStackTrace();
  }
  return retval;
}

代码示例来源:origin: qiujuer/Genius-Android

@Override
public void start() {
  Socket socket = null;
  try {
    Long startTime = System.currentTimeMillis();
    socket = new Socket();
    try {
      socket.setSoTimeout(TIME_OUT);
    } catch (SocketException e) {
      e.printStackTrace();
    }
    socket.connect(new InetSocketAddress(mHost, mPort), TIME_OUT);
    if (isConnected = socket.isConnected())
      mDelay = System.currentTimeMillis() - startTime;
    else
      mError = Cmd.TCP_LINK_ERROR;
  } catch (UnknownHostException e) {
    mError = Cmd.UNKNOWN_HOST_ERROR;
  } catch (IOException e) {
    mError = Cmd.TCP_LINK_ERROR;
  } finally {
    if (socket != null) {
      try {
        socket.close();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  }
}

代码示例来源:origin: jmdhappy/xxpay-master

/**
 * 兼容Linux系统
 * @return
 */
public static String getLocalIP() {
  String ip = "";
  try {
    Enumeration<?> e1 = (Enumeration<?>) NetworkInterface
        .getNetworkInterfaces();
    while (e1.hasMoreElements()) {
      NetworkInterface ni = (NetworkInterface) e1.nextElement();
      Enumeration<?> e2 = ni.getInetAddresses();
      while (e2.hasMoreElements()) {
        InetAddress ia = (InetAddress) e2.nextElement();
        if (ia instanceof Inet6Address)
          continue;
        if (!ia.isLoopbackAddress()) {
          ip = ia.getHostAddress();
          break;
        }
      }
    }
  } catch (SocketException e) {
    e.printStackTrace();
    return "";
  }
  return ip;
}

代码示例来源:origin: log4j/log4j

e.printStackTrace();
LogLog.error("Could not instantiate DatagramSocket to " + host +
    ". All logging will FAIL.", e);

代码示例来源:origin: apache/zookeeper

private void starter(QuorumPeer self) {
  this.self = self;
  port = self.getVotingView().get(self.getId()).electionAddr.getPort();
  proposedLeader = -1;
  proposedZxid = -1;
  try {
    mySocket = new DatagramSocket(port);
    // mySocket.setSoTimeout(20000);
  } catch (SocketException e1) {
    e1.printStackTrace();
    throw new RuntimeException();
  }
  sendqueue = new LinkedBlockingQueue<ToSend>(2 * self.getVotingView().size());
  recvqueue = new LinkedBlockingQueue<Notification>(2 * self.getVotingView()
      .size());
  new Messenger(self.getVotingView().size() * 2, mySocket);
}

代码示例来源:origin: Red5/red5-server

netInterfaces = NetworkInterface.getNetworkInterfaces();
} catch (SocketException e) {
  e.printStackTrace();

代码示例来源:origin: JZ-Darkal/AndroidHttpCapture

public String getMacAddress(String netInterface) {
  String strMacAddr = "";
  byte[] b;
  try {
    NetworkInterface NIC = NetworkInterface.getByName(netInterface);
    if (NIC == null) {
      NIC = NetworkInterface.getByName("rmnet0");//小米关掉Wifi后只剩下此网卡。
      strMacAddr = "没有 " + netInterface + " 网卡";
    }
    if (NIC != null) {
      b = NIC.getHardwareAddress();
      if (b == null) {
        return strMacAddr;
      }
      StringBuffer buffer = new StringBuffer();
      for (int i = 0; i < b.length; i++) {
        if (i != 0) {
          buffer.append(':');
        }
        String str = Integer.toHexString(b[i] & 0xFF);
        buffer.append(str.length() == 1 ? 0 + str : str);
      }
      strMacAddr = buffer.toString().toUpperCase();
    }
  } catch (SocketException e) {
    e.printStackTrace();
  }
  return strMacAddr;
}

代码示例来源:origin: apache/activemq

public Acceptor(ServerSocket serverSocket, URI uri) {
  socket = serverSocket;
  target = uri;
  pause.set(new CountDownLatch(0));
  try {
    socket.setSoTimeout(ACCEPT_TIMEOUT_MILLIS);
  } catch (SocketException e) {
    e.printStackTrace();
  }
}

代码示例来源:origin: org.apache.zookeeper/zookeeper

private void starter(QuorumPeer self) {
  this.self = self;
  port = self.getVotingView().get(self.getId()).electionAddr.getPort();
  proposedLeader = -1;
  proposedZxid = -1;
  try {
    mySocket = new DatagramSocket(port);
    // mySocket.setSoTimeout(20000);
  } catch (SocketException e1) {
    e1.printStackTrace();
    throw new RuntimeException();
  }
  sendqueue = new LinkedBlockingQueue<ToSend>(2 * self.getVotingView().size());
  recvqueue = new LinkedBlockingQueue<Notification>(2 * self.getVotingView()
      .size());
  new Messenger(self.getVotingView().size() * 2, mySocket);
}

代码示例来源:origin: android-hacker/VirtualXposed

private static IPInfo getIPInfo() {
  try {
    List<NetworkInterface> interfaces = Collections.list(NetworkInterface.getNetworkInterfaces());
    for (NetworkInterface intf : interfaces) {
      List<InetAddress> addrs = Collections.list(intf.getInetAddresses());
      for (InetAddress addr : addrs) {
        if (!addr.isLoopbackAddress()) {
          String sAddr = addr.getHostAddress().toUpperCase();
          boolean isIPv4 = isIPv4Address(sAddr);
          if (isIPv4) {
            IPInfo info = new IPInfo();
            info.addr = addr;
            info.intf = intf;
            info.ip = sAddr;
            info.ip_hex = InetAddress_to_hex(addr);
            info.netmask_hex = netmask_to_hex(intf.getInterfaceAddresses().get(0).getNetworkPrefixLength());
            return info;
          }
        }
      }
    }
  } catch (SocketException e) {
    e.printStackTrace();
  }
  return null;
}

代码示例来源:origin: qiujuer/Genius-Android

} catch (SocketException e) {
  mError = Cmd.NETWORK_SOCKET_ERROR;
  e.printStackTrace();
} catch (IOException e) {
  mError = Cmd.NETWORK_IO_ERROR;

代码示例来源:origin: alibaba/TProfiler

e.printStackTrace();
} catch (IOException e) {
  e.printStackTrace();

代码示例来源:origin: jiangqqlmj/FastDev4Android

e.printStackTrace();
} catch (SocketException e) {
  e.printStackTrace();

代码示例来源:origin: LaiFeng-Android/SopCastComponent

socket.setSendBufferSize(size);
} catch (SocketException e) {
  e.printStackTrace();

代码示例来源:origin: org.apache.thrift/libthrift

public void listen() throws TTransportException {
 // Make sure not to block on accept
 if (serverSocket_ != null) {
  try {
   serverSocket_.setSoTimeout(0);
  } catch (SocketException sx) {
   sx.printStackTrace();
  }
 }
}

代码示例来源:origin: fossasia/neurolab-desktop

public void setOSCInput(int port)
{
  try
  {
    receiver = new OSCPortIn(port);
    
  } catch (SocketException e)
  {
    e.printStackTrace();
  }
}

代码示例来源:origin: fossasia/neurolab-desktop

public void setOSCInput(int port)
{
  try
  {
    receiver = new OSCPortIn(port);
    
  } catch (SocketException e)
  {
    e.printStackTrace();
  }
}

代码示例来源:origin: sixt/ja-micro

private void updateIpAddress() {
  try {
    Enumeration<NetworkInterface> b = NetworkInterface.getNetworkInterfaces();
    ipAddress = null;
    while( b.hasMoreElements()){
      NetworkInterface iface = b.nextElement();
      if (iface.getName().startsWith("dock")) {
        continue;
      }
      for ( InterfaceAddress f : iface.getInterfaceAddresses()) {
        if (f.getAddress().isSiteLocalAddress()) {
          ipAddress = f.getAddress().getHostAddress();
        }
      }
    }
  } catch (SocketException e) {
    e.printStackTrace();
  }
}

代码示例来源:origin: winder/Universal-G-Code-Sender

/**
 * Thread to accept data from remote host, and pass it to responseHandler
 */
public void run() {
  String resp;
  while(!Thread.interrupted() && !client.isClosed())
  {
    try {
      if(inStream.ready() && (resp = bufIn.readLine()) != null) {
        responseMessageHandler.handleResponse(resp + "\n", comm);
      }
    } catch (SocketException e) {
      e.printStackTrace();
      return; // terminate thread if disconnected
          //TODO: at some point, reconnecting should be considered
    } catch (IOException e) {
      e.printStackTrace();
      return; // terminate thread if disconnected
          //TODO: at some point, reconnecting should be considered
    }
  }
}

代码示例来源:origin: yuliskov/SmartYouTubeTV

private boolean testIPv4() {
    try {
      Enumeration<NetworkInterface> networks = NetworkInterface.getNetworkInterfaces();
      while (networks.hasMoreElements()) {
        NetworkInterface network = networks.nextElement();
        for (InterfaceAddress address : network.getInterfaceAddresses()) {
          if (address.getAddress() instanceof Inet4Address) {
            // found IPv4 address
            // do any other validation of address you may need here
            return true;
          }
        }
      }
      return false;
    } catch (SocketException e) {
      e.printStackTrace();
      throw new IllegalStateException(e);
    }
  }
}

相关文章