BytesRoad.Net.Sockets.SocketBase.ConstructEndPoint C# (CSharp) Method

ConstructEndPoint() static private method

static private ConstructEndPoint ( IPHostEntry host, int port ) : IPEndPoint
host System.Net.IPHostEntry
port int
return System.Net.IPEndPoint
        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);
        }

Usage Example

Exemplo n.º 1
0
        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();
            }
        }
All Usage Examples Of BytesRoad.Net.Sockets.SocketBase::ConstructEndPoint