Here you can find the source of stringToInetSocketAddress( String address, int defaultPort)
Parameter | Description |
---|---|
address | String which represents the address in format "hostname:port". |
defaultPort | Port that is used if address String is just a hostname. |
static protected InetSocketAddress stringToInetSocketAddress( String address, int defaultPort)
//package com.java2s; /*/*from w w w.j av a 2s .c om*/ * Copyright (c) 2008-2011 by Paul Seiferth, Zuse Institute Berlin * * Licensed under the BSD License, see LICENSE file for details. * */ import java.net.InetSocketAddress; public class Main { /** * Converts a address in format "hostname:port" to a InetSocketAddress * * @param address * String which represents the address in format "hostname:port". * @param defaultPort * Port that is used if address String is just a hostname. */ static protected InetSocketAddress stringToInetSocketAddress( String address, int defaultPort) { InetSocketAddress isa; int pos = 0; if ((pos = address.indexOf(':')) == -1) { isa = new InetSocketAddress(address, defaultPort); } else { isa = new InetSocketAddress(address.substring(0, pos), Integer.parseInt(address.substring(pos + 1))); } return isa; } }