private static void EstablishConnection(IntradomainChannel channel,
                                                AutoResetEvent channelCreatedEvent,
                                                IntradomainSocket socket,
                                                TimeSpan connectTimeout)
        {
            // release waiting client
            channelCreatedEvent.Set();

            channel._connectionManager.WaitForConnection(socket.ConnectionId, (int)connectTimeout.TotalMilliseconds);

            channel.ResponseHandshake();
        }
        internal static IntradomainChannel CreateAndOpen(AutoResetEvent channelCreatedEvent,
                                                         IntradomainSocket socket,
                                                         IMessageSerializer serializer,
                                                         ChannelSettings channelSettings = null,
                                                         IntradomainConnectionSettings connectionSettings = null,
                                                         ISecurityWrapper serverSecurityWrapper           = null)
        {
            var result = new IntradomainChannel(socket, serializer, channelSettings, connectionSettings, serverSecurityWrapper);

            EstablishConnection(result, channelCreatedEvent, socket, connectionSettings?.ConnectTimeout ?? IntradomainConnectionSettingsBuilder.GetDefaultSettings().ConnectTimeout);
            return(result);
        }
        protected override IntradomainChannel CreateChannel(IMessageSerializer serializer)
        {
            return(ChannelSettings != null
                ? IntradomainChannel.CreateAndOpen <TMessage>(ChannelCreated,
                                                              ServerSocket,
                                                              serializer,
                                                              ChannelSettings,
                                                              ConnectionSettings,
                                                              ServerSecurityWrapper)

                : IntradomainChannel.CreateAndOpen <TMessage>(ChannelCreated,
                                                              ServerSocket,
                                                              serializer));
        }