Ejemplo n.º 1
0
 private void Listen()
 {
     ThreadPool.QueueUserWorkItem(delegate
     {
         Socket listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
         listener.Bind(FileTransmiter.RealEndPoint);
         listener.Listen(FileTransmiter.MaxThreadCount);
         while (true)
         {
             if (listener.Blocking)
             {
                 Socket client = listener.Accept();
                 if (this.InvokeRequired)
                 {
                     this.Invoke(new Action <Socket>(AddClient), client);
                 }
                 else
                 {
                     AddClient(client);
                 }
                 worker = new FileTransmiter.ReceiveWorker(client);
                 FileTransmiter.SupperReceive(client, ConfigurationManager.AppSettings["path"], worker, new Action <string, int, bool, double>(ReportStatus), new Action <string, long>(ReportSpeed));
             }
         }
     });
 }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            Console.Write("Plz type in a file path.");
            string file = Console.ReadLine();

            //FileTransmiter.Send(FileTransmitor.TestIP, file);
            FileTransmiter.SendWorker worker = new FileTransmiter.SendWorker(FileTransmiter.TestEndPoint);
            FileTransmiter.SupperSend(FileTransmiter.TestEndPoint, file, worker);
            Console.ReadLine();
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            //FileTransmiter.Receive(FileTransmitor.TestIP, @"E:\");//接受放到那个盘里 保存路径=这个参数+发送到文件名。
            Socket listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            listener.Bind(FileTransmiter.TestEndPoint);
            listener.Listen(FileTransmiter.MaxThreadCount);
            FileTransmiter.ReceiveWorker worker = new FileTransmiter.ReceiveWorker(listener.Accept());
            FileTransmiter.SupperReceive(listener, @"F:\Test", worker);
            Console.ReadLine();
        }
Ejemplo n.º 4
0
 public SendArgs(string file, FileTransmiter.SendWorker worker)
 {
     this.file = file;
     this.worker = worker;
 }
Ejemplo n.º 5
0
 private void SendFile(string file, FileTransmiter.SendWorker worker)
 {
     if (File.Exists(file))
     {
         ThreadPool.QueueUserWorkItem(new WaitCallback(Send), new SendArgs(file, worker));
     }
     else
     {
         MessageBox.Show("指定的文件[" + file + "]不存在!");
     }
 }
Ejemplo n.º 6
0
        private void Send(object o)
        {
            SendArgs arg = o as SendArgs;

            FileTransmiter.SupperSend(FileTransmiter.RealEndPoint, arg.File, arg.Worker, new Action <string, int, bool, double>(ReportStatus), new Action <string, long>(ReportSpeed));
        }