コード例 #1
0
        /////////////////////////////////////////////////////////////////////////////////////////////
        #region // Public Methods

        /// <summary>
        /// Initializes a udpclient with the specified host and port. The callback function is then invoked with the initialized client.
        /// </summary>
        public override void Start(Action <IConnectionMode> callback)
        {
            if (!this.listening)
            {
                this.listening = true;
                IConnectionMode mode = this.GetMode(this.connectionString.Mode, new Udp(this.connectionString.Host, this.connectionString.Port));
                new Thread(() => { callback(mode); }).Start();
            }
        }
コード例 #2
0
ファイル: RemoteSpace.cs プロジェクト: messyoxd/ChatTupla
        private IConnectionMode GetMode()
        {
            switch (this.connectionString.Mode)
            {
            case ConnectionMode.KEEP: lock (this.connectionString) { this.mode = this.mode ?? new Keep(this.GetProtocol(), this.encoder); } break;

            case ConnectionMode.CONN: return(new Conn(this.GetProtocol(), this.encoder));

            case ConnectionMode.PUSH: return(new Push(this.GetProtocol(), this.encoder));

            case ConnectionMode.PULL: return(new Pull(this.GetProtocol(), this.encoder));

            default: return(null);
            }
            return(this.mode);
        }
コード例 #3
0
        /////////////////////////////////////////////////////////////////////////////////////////////
        #region // Private Methods

        private void Listen()
        {
            this.listener.Start(this.backlog);
            Console.WriteLine("Current endpoint: {0}:{1}", this.ipAddress.ToString(), this.connectionString.Port);
            Console.WriteLine("Begin listening...");
            try
            {
                while (this.listening)
                {
                    TcpClient       client   = listener.AcceptTcpClient();
                    Tcp             protocol = new Tcp(client);
                    IConnectionMode mode     = this.GetMode(this.connectionString.Mode, protocol);
                    new Thread(() => { this.callBack(mode); }).Start();
                }
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                listener.Stop();
            }
        }
コード例 #4
0
        /////////////////////////////////////////////////////////////////////////////////////////////
        #region // Protected Methods

        /// <summary>
        /// Processes the incoming connection using the internal operation map.
        /// </summary>
        protected override void OnConnect(IConnectionMode mode)
        {
            mode?.ProcessRequest(this.operationMap);
        }
コード例 #5
0
        /////////////////////////////////////////////////////////////////////////////////////////////
        #region // Protected Methods

        /// <summary>
        /// Template method that is called when the repository receives an incoming connection.
        /// </summary>
        protected abstract void OnConnect(IConnectionMode mode);