public static T WaitForClient <T, U>(
            this INodeEndpointProtocolFactory protocolFactory,
            string address,
            string endpointName,
            U callback,
            int timeout = 5000
            )
            where T : IDuplexNodeEndpointClient <U>
            where U : INodeEndpoint
        {
            T client = WaitForClient <T>(protocolFactory, address, endpointName, timeout);

            if (!object.ReferenceEquals(client, default(T)))
            {
                if (client.Provider.Protocol.EnableDuplex)
                {
                    INodeEndpointProtocolRequestListener endpointListener = new ProtocolEnabledRequestListener(callback);
                    client.Provider.Protocol.AddListener(endpointListener);
                    client.Callback = callback;
                }
                else
                {
                    client.Dispose();
                    throw new InvalidOperationException("The protocol does not support duplex communication.");
                }
            }
            return(client);
        }
        private static INodeEndpointProtocolServer WaitForServerBase(
            this INodeEndpointProtocolServerListener serverListener,
            string address,
            INodeEndpoint endpoint,
            int timeout
            )
        {
            if (!serverListener.Connected)
            {
                serverListener.Connect(address, endpoint.EndpointName);
            }
            INodeEndpointProtocolServer server = serverListener.Listen(timeout);

            if (server != null)
            {
                INodeEndpointProtocolRequestListener endpointListener = new ProtocolEnabledRequestListener(endpoint);
                server.AddListener(endpointListener);
            }
            return(server);
        }