/**
  * Connect via a proxy.
  *
  * @throws SocketException
  * @throws IOException
  */
 private void connectViaProxy() throws NetworkException, SocketException, IOException {
   socket = newSocket();
   if (Boolean.FALSE == protocol.isSecure()) {
     /* secure sockets must already be connected */
     socket.connect(networkImpl.lookupSocketAddress(address), getConnectTimeout());
   }
 }
 /**
  * Create a new socket.
  *
  * @return A <code>Socket</code>.
  */
 private Socket newSocket() throws NetworkException, UnknownHostException {
   if (protocol.isSecure()) {
     return networkImpl.newSecureSocket(id, proxy, address);
   } else {
     return networkImpl.newSocket(id, proxy);
   }
 }
 /** @see com.thinkparity.network.NetworkConnection#disconnect() */
 @Override
 public void disconnect() {
   logger.logTraceId();
   logger.logInfo("{0} - Disconnect", getId());
   if (isConnected()) {
     try {
       if (Boolean.FALSE == protocol.isSecure()) {
         socket.shutdownInput();
       }
     } catch (final IOException iox) {
       logger.logWarning(iox, "{0} - Error disconnecting.", getId());
     } finally {
       try {
         if (Boolean.FALSE == protocol.isSecure()) {
           socket.shutdownOutput();
         }
       } catch (final IOException iox) {
         logger.logWarning(iox, "{0} - Error disconnecting.", getId());
       } finally {
         try {
           socket.close();
         } catch (final IOException iox) {
           logger.logWarning(iox, "{0} - Error disconnecting.", getId());
         } finally {
           socket = null;
           input = null;
           output = null;
           logger.logInfo("{0} - Disconnected", getId());
           connected = false;
         }
       }
     }
   } else {
     logger.logWarning("{0} - Is not connected.", getId());
   }
 }
 public static void checkForNewUDPConnections() {
   SocketAddress connection = null;
   ByteBuffer bb = ByteBuffer.allocate(65507);
   try {
     while ((connection = serverUDPConChannel.receive(bb)) != null) {
       System.out.println("Position " + bb.position());
       bb.flip();
       System.out.println("Packet Received");
       System.out.println("BB LIMIT: " + bb.limit());
       for (int i = 0; i < bb.limit(); i++) {
         System.out.println("Value " + i + ": " + bb.get(i));
       }
       if (bb.array()[0] == GAME_INFO && bb.array()[1] == NetworkProtocol.GAME_INFO_HEARTBEAT)
         for (int i = 0; i < attemptedConnections.size(); i++) {
           System.out.println("1: " + connection.toString());
           System.out.println(
               "2: "
                   + attemptedConnections
                       .get(i)
                       .getTCPConnection()
                       .socket()
                       .getRemoteSocketAddress()
                       .toString());
           if (NetworkProtocol.IPsEqual(
               connection,
               attemptedConnections.get(i).getTCPConnection().socket().getRemoteSocketAddress())) {
             DatagramChannel d = DatagramChannel.open();
             d.configureBlocking(false);
             d.connect(connection);
             attemptedConnections.get(i).setUDPConnection(d);
             byte[] response = {GAME_INFO, GAME_INFO_HEARTBEAT};
             d.write(ByteBuffer.wrap(response));
             System.out.println("Equal");
           }
         }
       bb.clear();
     }
   } catch (IOException e) {
     e.printStackTrace();
   }
 }