private AddressFamily addressFamily = AddressFamily.InterNetwork;
//判断是域名还是IP
if (System.Text.RegularExpressions.Regex.Matches(this.address, "[a-zA-Z]").Count > 0)
{
IPHostEntry ipHostInfo = Dns.GetHostEntry(this.address);
for (int i = 0; i < ipHostInfo.AddressList.Length; i++)
{
if (ipHostInfo.AddressList[i].AddressFamily == AddressFamily.InterNetworkV6) //是ipv6
{
ipAddress = ipHostInfo.AddressList[i];
addressFamily = AddressFamily.InterNetworkV6;
break;
}
}
if (ipAddress == null)
{
ipAddress = ipHostInfo.AddressList[0];
}
}
else
{
if (!IPAddress.TryParse(this.address, out ipAddress))
throw new ArgumentException("Provided remoteIPAddress string was not successfully parsed.", "remoteIPAddress");
}
socket = new Socket(addressFamily, SocketType.Stream, ProtocolType.Tcp);