static private ConstructEndPoint ( |
||
host | ||
port | int | |
return |
static internal IPEndPoint ConstructEndPoint(IPHostEntry host, int port)
{
if(0 >= host.AddressList.Length)
{
NSTrace.WriteLineError("Provided host structure do not contains addresses.");
throw new ArgumentException("Provided host structure do not contains addresses.", "host");
}
foreach (var addr in host.AddressList)
{
if (addr.AddressFamily == AddressFamily.InterNetwork)
return new IPEndPoint(addr, port);
}
return new IPEndPoint(IPAddress.Parse("127.0.0.1"), port);
}
void GetHost_End(IAsyncResult ar) { Connect_SO stateObj = (Connect_SO)ar.AsyncState; try { stateObj.UpdateContext(); IPHostEntry host = Dns.EndGetHostByName(ar); if (null == host) { throw new SocketException(SockErrors.WSAHOST_NOT_FOUND); } //throw new HostNotFoundException("Unable to resolve host name."); EndPoint remoteEP = SocketBase.ConstructEndPoint(host, stateObj.Port); _socket.BeginConnect(remoteEP, new AsyncCallback(Connect_End), stateObj); } catch (Exception e) { stateObj.Exception = e; stateObj.SetCompleted(); } }