Java Socket Address Get getDestination(InetSocketAddress server)

Here you can find the source of getDestination(InetSocketAddress server)

Description

get Destination

License

Open Source License

Declaration

public static InetSocketAddress getDestination(InetSocketAddress server) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2016 Bosch Software Innovations GmbH and others.
 * //from w  w w .ja va2s .  c  o m
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * and Eclipse Distribution License v1.0 which accompany this distribution.
 * 
 * The Eclipse Public License is available at
 *    http://www.eclipse.org/legal/epl-v10.html
 * and the Eclipse Distribution License is available at
 *    http://www.eclipse.org/org/documents/edl-v10.html.
 * 
 * Contributors:
 *    Achim Kraus (Bosch Software Innovations GmbH) - initial implementation
 *                                                    stuff copied from TcpConnectorTest
 *    Achim Kraus (Bosch Software Innovations GmbH) - adjust creation of oubound message
 *                                                    with null correlation context.
 *    Achim Kraus (Bosch Software Innovations GmbH) - add sending correlation context.
 *    Achim Kraus (Bosch Software Innovations GmbH) - replace "any/0.0.0.0" with 
 *                                                    "localhost/127.0.0.1" in destination.
 *    Achim Kraus (Bosch Software Innovations GmbH) - add create server address
 *                                                    using LoopbackAddress.
 ******************************************************************************/

import java.net.InetAddress;
import java.net.InetSocketAddress;

public class Main {
    public static InetSocketAddress getDestination(InetSocketAddress server) {
        if (server.getAddress().isAnyLocalAddress()) {
            // for destination replace any by localhost
            server = new InetSocketAddress(InetAddress.getLoopbackAddress(), server.getPort());
        }
        return server;
    }
}

Related

  1. getBestAddress(InetSocketAddress addr)
  2. getCanonicalConnectionAddress(InetSocketAddress address)
  3. getClientPort(SocketAddress socketAddress)
  4. getConnectAddress(InetSocketAddress addr)
  5. getConnString(SocketAddress address)
  6. getDestinationInetSocketAddress(URI uri, int defaultPort)
  7. getHostAddress(InetSocketAddress addr)
  8. getHostAddress(InetSocketAddress address)
  9. getHostName(SocketAddress socketAddress)