コード例 #1
0
 @Override
 public void connect(InetAddress inetAddr, int port) throws SocketException {
   IoBridge.connect(fd, inetAddr, port); // Throws on failure.
   try {
     connectedAddress = InetAddress.getByAddress(inetAddr.getAddress());
   } catch (UnknownHostException e) {
     // this is never expected to happen as we should not have gotten
     // here if the address is not resolvable
     throw new SocketException("Host is unresolved: " + inetAddr.getHostName());
   }
   connectedPort = port;
   isNativeConnected = true;
 }
コード例 #2
0
 @Override
 protected int peek(InetAddress sender) throws IOException {
   // We don't actually want the data: we just want the DatagramPacket's filled-in address.
   DatagramPacket packet = new DatagramPacket(EmptyArray.BYTE, 0);
   int result = peekData(packet);
   // Note: evil side-effect on InetAddress! This method should have returned InetSocketAddress!
   sender.ipaddress = packet.getAddress().getAddress();
   return result;
 }