Ejemplo n.º 1
0
        /// <summary>
        /// Creates a listener than can be connected to by other agents.
        /// </summary>
        /// <param name="endpoint">The endpoint the agent is to be exposed on.</param>
        /// <param name="connectionOpenedHandler">The observer that will receive connection events from the listener.</param>
        /// <returns>An asynchronous task that returns a Listener result.</returns>
        public static Task <Listener> AgentListenAsync(string endpoint, ConnectionOpenedHandler connectionOpenedHandler)
        {
            var taskCompletionSource = new TaskCompletionSource <Listener>();
            var commandHandle        = AddTaskCompletionSource(taskCompletionSource);

            AddConnectionOpenedHandler(commandHandle, connectionOpenedHandler);

            var result = IndyNativeMethods.indy_agent_listen(
                commandHandle,
                endpoint,
                _listenerCreatedCallback,
                _listenerConnectionEstablishedCallback,
                _agentListenerMessageReceivedCallback);

            CheckResult(result);

            return(taskCompletionSource.Task);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a new AgentListener that listens for incoming connections on the specified endpoint.
        /// </summary>
        /// <remarks>
        /// The endpoint specified must be in the format <c>address:port</c> where <c>address</c> is
        /// an IP address or host address and <c>port</c> is a numeric port number.
        /// </remarks>
        /// <param name="endpoint">The endpoint on which the incoming connections will listened for.</param>
        /// <returns>An asynchronous <see cref="Task{T}"/> that resolves to an AgentListener instance
        /// once the listener has been created.</returns>
        public static Task <AgentListener> ListenAsync(string endpoint)
        {
            var listener = new AgentListener();

            var taskCompletionSource = new TaskCompletionSource <AgentListener>(listener);
            var commandHandle        = PendingCommands.Add(taskCompletionSource);

            var result = IndyNativeMethods.indy_agent_listen(
                commandHandle,
                endpoint,
                _listenerCreatedCallback,
                listener.ConnectionEstablishedCallback,
                listener.MessageReceivedCallback);

            CallbackHelper.CheckResult(result);

            return(taskCompletionSource.Task);
        }