Get a cached socket to the given address
@param remote  Remote address the socket is connected to.
@return  A socket with unknown state, possibly closed underneath. Or null.
1876
public Socket get(SocketAddress remote) {
    synchronized(multimap) {
      List<Socket> sockList = multimap.get(remote);
      if (sockList == null) {
        return null;
      }
      
      Iterator<Socket> iter = sockList.iterator();
      while (iter.hasNext()) {
        Socket candidate = iter.next();
        iter.remove();
        if (!candidate.isClosed()) {
          return candidate;
        }
      }
    }
    return null;
  }
1302696
@Override
  public InetAddress addressLocal()
  {
    Socket s = getSocket();
    
    if (s != null) {
      return s.getLocalAddress();
    }
    else {
      return null;
    }
  }
678430
public String remoteIP(){
        String remoteAddr = request.getRemoteAddr();
        
        // This could be a list of proxy IPs, which the developer could
        // provide via some configuration
        if ("127.0.0.1".equals(remoteAddr)) remoteAddr = requestHeader("X-Forwarded-For");
        return remoteAddr;
    }
15255
public synchronized void setCache(RemoteListCache cache) {
		if (cache != null && (this.cache == null || !this.cache.isComplete())) {
			this.cache = cache;
		}
	}
196351
public void put(Socket sock) {
    Preconditions.checkNotNull(sock);
    
    SocketAddress remoteAddr = sock.getRemoteSocketAddress();
    if (remoteAddr == null) {
      LOG.warn("Cannot cache (unconnected) socket with no remote address: " + 
               sock);
      IOUtils.closeSocket(sock);
      return;
    }
   
    Socket oldestSock = null;
    synchronized(multimap) {
      if (capacity == multimap.size()) {
        oldestSock = evictOldest();
      }
      multimap.put(remoteAddr, sock);
    }
    
    if (oldestSock != null) {
      IOUtils.closeSocket(oldestSock);
    }
  }
44876
public String getRemoteHost()
  {
    InetAddress remoteAddress = addressRemote();
    
    if (remoteAddress != null)
      return remoteAddress.getHostAddress();
    else
      return null;
  }
145961
public static String remoteHost(HttpHeaders headers, Channel channel) {
        requireNonNull(headers, "headers");
        requireNonNull(channel, "channel");
        String host = headers.authority();
        if (host == null) {
            host = ((InetSocketAddress) channel.remoteAddress()).getHostString();
        } else {
            final int colonIdx = host.lastIndexOf(':');
            if (colonIdx > 0) {
                host = host.substring(0, colonIdx);
            }
        }
        return host;
    }
956200
protected Socket getSocket(){
        if (mSocketFactoryRef != null && mSocketFactoryRef.get() != null) {
            return ((SSLSocketFactoryWrapper)mSocketFactoryRef.get()).getSocket();
        }
        return null;
    }
742472
public static RemoteRepository remoteRepositoryFromUrl(String url) throws MalformedURLException {
        URL parsedUrl = new URL(url);

        StringBuffer id = new StringBuffer(parsedUrl.getHost());
        String path = parsedUrl.getPath();
        if (path.length() > 0) {
            path = path.replaceFirst("/", "").replaceAll("/", "-").replaceAll(":", "-");
            id.append("-");
            id.append(path);
        }

        if (parsedUrl.getPort() > -1) {
            id.append("-");
            id.append(parsedUrl.getPort());
        }

        return new RemoteRepository(id.toString(), "default", url);
    }
1310372
public static InetAddress getRemoteIp() {
    Call call = CurCall.get();
    if (call != null) {
      return call.connection.socket.getInetAddress();
    }
    return null;
  }
686125
public static RemoteTable getRemoteTableType(RemoteTable tableRemote, Class<?> classType)
   {
       if ((classType == null) || (tableRemote == null) || (classType.isAssignableFrom(tableRemote.getClass())))
           return tableRemote;
       RemoteTable remoteTable = null;
       if (!(tableRemote instanceof org.jbundle.model.Remote)) // No need to actually do the remote call
           if (!(tableRemote instanceof RemoteObject))
               if (!(tableRemote instanceof java.lang.reflect.Proxy)) // No need to actually do the remote call
       {
           try {
               remoteTable = tableRemote.getRemoteTableType(classType);
           } catch (RemoteException ex)    {
               // Never.
           }
       }
       if (classType == org.jbundle.model.Remote.class)  // Yeah I know this has already been done, but it is possible the EJB server may be forcing me to use a proxy
           if (remoteTable == null)
               return tableRemote;    // If you're asking for the last in the chain, that's me
       return remoteTable;
   }
1032983
public void connectRtcp(SocketAddress remoteAddress) {
		this.rtcpChannel.setRemotePeer(remoteAddress);
		
		if(logger.isDebugEnabled()) {
			logger.debug(this.mediaType + " RTCP channel " + this.ssrc + " has connected to remote peer " + remoteAddress.toString());
		}
	}
1096844
public Socket getSocket(URI uri, boolean wantTLS) throws Exception
	{
		if (uri == null) {
			throw new URISyntaxException("", "The URI specified cannot be null");
		}
		
		// Get the registered security domain for the URI
		SecurityDomain securityDomain = null;
		if (wantTLS) {
			securityDomain = CONTEXT.getSecurityDomainManager().getSecurityDomain(uri);
		}
		return getSocket(uri,wantTLS,securityDomain);
	}
1330319
private HttpClient getTemplateServerClient(String remoteSource) throws IOException {

		// TODO: this was copied from the RemoteCompiler class.  This needs
		//       to be moved into a location where both can access it!
		int port = 80;
		String host = remoteSource.substring(RemoteCompilationProvider.TEMPLATE_LOAD_PROTOCOL.length());

		int portIndex = host.indexOf("/");
    
		if (portIndex >= 0) {
			host = host.substring(0,portIndex);                         
		}
		portIndex = host.indexOf(":");
		if (portIndex >= 0) {
			try {
				port = Integer.parseInt(host.substring(portIndex+1));
			}
			catch (NumberFormatException nfe) {
				System.out.println("Invalid port number specified");
			}
			host = host.substring(0,portIndex);
		}
		// TODO: remove the hardcoded 15 second timeout!
		SocketFactory factory = new PooledSocketFactory
			(new PlainSocketFactory(InetAddress.getByName(host), port, 15000));
        
		return new HttpClient(factory);
	}
1364469
public CompletableFuture<Connection> getConnection(Address address) {
    Connection connection = connections.get(address);
    return connection == null ? createConnection(address) : CompletableFuture.completedFuture(connection);
  }
195115
public RemoteTable getRemoteTableType(Class<?> classType) throws RemoteException
    {
        if (org.jbundle.model.Remote.class.getName().equals(classType.getName()))
            return this;    // For this purpose I am the remote object.
        return null;    // This method is never called remotely
    }
510543
private String resolveHostName(InetSocketAddress remoteAddress) {
        String hostString = null;
        try {
            hostString = (String) getHostMethod.invoke(remoteAddress, new Object[]{});
        } catch (InvocationTargetException ite) {
            throw new RuntimeException("Expecting InetSocketAddress to have a package scoped \"getHostString\" method which returns a String and takes no input");
        } catch (IllegalAccessException iae) {
            throw new RuntimeException("Expecting InetSocketAddress to have a package scoped \"getHostString\" method which returns a String and takes no input");
        }
        return hostString;
    }