/*
* GNU GENERAL PUBLIC LICENSE
* Version 2, June 1991
*
*
*
* ADDITIONAL REQUIREMENT
*
* 1. If PeerfactSim.KOM is used for the evaluation in research publications,
* the following should be referenced:
*
* @techreport{ PWLS07,
* author = {Konstantin Pussep and Matthias Weinert and Nicolas Liebau and Ralf Steinmetz},
* title = {Flexible Framework for NAT Traversal in Peer-to-Peer Applications},
* month = {Nov},
* year = {2007},
* institution = {KOM - Multimedia Communications Lab, Technische Universit{\"a}t Darmstadt},
* address = {Merckstra{\ss}e 25, 64283 Darmstadt, Germany},
* number = {KOM-TR-2007-06},
* }
*/
//package com.nowjava;//来自 时 代 J a v a 公 众 号
import java.net.InetSocketAddress;
public class Main {
public static void main(String[] argv) throws Exception {
String addrString = "nowjava.com";
System.out.println(parseSocketAddress(addrString));
}
/**
* Parses the string and returns a <tt>InetSocketAddress</tt>. Address must have the format
* <tt>hostname:port</tt>.
*
* @param addrString a string of a hostname and port
* @return corresponding InetSocketAddress
*/
public static InetSocketAddress parseSocketAddress(String addrString) {
return parseSocketAddress(addrString, -1);
}
/**
* Parses the string and returns a <tt>InetSocketAddress</tt>. Address can have the format
* <tt>hostname:port</tt> or only <tt>hostname</tt>, then the <tt>defaultPort</tt> is used.
*
* @param addrString a string of a hostname and port
* @return corresponding InetSocketAddress
*/
/*
来 自*
n o w j a v a . c o m
*/
public static InetSocketAddress parseSocketAddress(String addrString,
int defaultPort) {
try {
/**代码未完, 请加载全部代码(NowJava.com).**/
本文系作者在时代Java发表,未经许可,不得转载。如有侵权,请联系nowjava@qq.com删除。