예제 #1
0
        private void LaunchClientBroker(FTPClientBroker broker)
        {
            ThreadStart ths = new ThreadStart(broker.Start);
            Thread      thd = new Thread(ths);

            thd.Start();

            GlobalRuntime.Threads.Add(thd);
        }
예제 #2
0
        public static FTPClientBroker GetOrCreateClientBrokerByDataClient(TcpClient dataClient)
        {
            string remoteIp = Convert2IP(dataClient.Client.RemoteEndPoint.ToString());

            if (!Brokers.ContainsKey(remoteIp))
            {
                FTPClientBroker broker = new FTPClientBroker();
                broker.DataTcpClient = dataClient;
                Brokers[remoteIp]    = broker;
            }
            Brokers[remoteIp].DataTcpClient = dataClient;
            return(Brokers[remoteIp]);
        }
예제 #3
0
        public void ProcessDataClientArrival(IAsyncResult iar)
        {
            TcpListener listener = (TcpListener)iar.AsyncState;
            TcpClient   client   = listener.EndAcceptTcpClient(iar);

            Monitor.Enter(this);
            FTPClientBroker broker = FTPClientBrokerFactory.GetOrCreateClientBrokerByDataClient(client);

            if (IsLaunchable(broker))
            {
                broker.NewTextMessageArrival += broker_NewTextMessageArrival;
                broker.FileTransferNotify    += broker_FileTransferNotify;
                LaunchClientBroker(broker);
            }
            Monitor.Exit(this);

            if (this.NewDataClientConnected != null)
            {
                this.NewDataClientConnected.Invoke(client.Client.RemoteEndPoint.ToString());
            }
        }
예제 #4
0
 private bool IsLaunchable(FTPClientBroker broker)
 {
     return(broker.CommandTcpClient != null && broker.DataTcpClient != null);
 }