Esempio n. 1
0
        //
        // Returns false if we are in an inappropriate state to retrieve the
        // remote endpoint
        //
        private bool GetRemoteEndPoint(out IPv4 localIP, out ushort localPort)
        {
            localIP   = new IPv4(0);
            localPort = 0;

            TcpConnectionContract /*.Imp*/ conn = GetChannelOrThrow();

            try {
                // Need to be connected for the remote endpoint to be defined
                if (!IsConnected(conn))
                {
                    return(false);
                }

                localIP   = conn.GetRemoteAddress();
                localPort = conn.GetRemotePort();
                return(true);
            }
            finally {
                ReleaseChannel(conn);
            }
        }
Esempio n. 2
0
        //
        // Returns false if we are in an inappropriate state to retrieve the
        // local endpoint
        //
        private bool GetLocalEndPoint(out IPv4 localIP, out ushort localPort)
        {
            localIP   = new IPv4(0);
            localPort = 0;

            TcpConnectionContract /*.Imp*/ conn = GetChannelOrThrow();

            try {
                // We need to be connected or listening to retrieve the local
                // endpoint
                if ((!conn.InState(TcpConnectionContract.State.Listening /*.Value*/)) &&
                    (!IsConnected(conn)))
                {
                    return(false);
                }

                localIP   = conn.GetLocalAddress();
                localPort = conn.GetLocalPort();
                return(true);
            }
            finally {
                ReleaseChannel(conn);
            }
        }