Beispiel #1
0
        //发送监听
        public void listen(int id)
        {
            int index = GetFileIndex(id);
            IPAddress[] ih = Dns.GetHostAddresses(TalkUser.ip);       //获得IP列表
            IPAddress UserIp = ih[0];      //获取IP地址    
            IPEndPoint Conncet = new IPEndPoint(UserIp, Port);     //构造结点
            SendFileSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);      //初始化socket 

            try
            {
                SendFileSocket.Connect(Conncet);      //连接远程服务器
                if (SendFileSocket.Connected)         //如果连接成功 s.Connected 则为true 否则为 false
                {
                    //MessageBox.Show("连接成功");
                    SaveFile sf = new SaveFile();
                    sf.index = index;
                    sf.path = filelist[index].filepath;
                    filelist[index].ShowSpeed = Visibility.Visible;

                    Thread t = new Thread(new ParameterizedThreadStart(SendFile)); //创建进程
                    t.Start(sf);                                   //开始进程
                }
            }
            catch (NullReferenceException e)
            {
                MessageBox.Show(e.ToString());
            }
        }
Beispiel #2
0
 //同意接收文件
 private void AcceptRecvFileClick(object sender, RoutedEventArgs e)
 {
     Button clickbutton = (Button)sender;
     int id = Int32.Parse(clickbutton.BorderThickness.ToString().Substring(0, 1));
     int index = GetFileIndex(id);
     if (index != -1)
     {
         SaveFileDialog dlg = new SaveFileDialog();
         dlg.FileName = filelist[index].name;
         dlg.Title = "另存为";
         dlg.Filter = "所有文件(*.*)|*.*";//文件扩展名
         if ((bool)dlg.ShowDialog().GetValueOrDefault())//打开
         {
             //MessageBox.Show(dlg.FileName);
             filelist[index].ShowButton1 = Visibility.Hidden;
             filelist[index].ShowSpeed = Visibility.Visible;
             File_List.ItemsSource = null;
             File_List.ItemsSource = filelist;
             SaveFile sf = new SaveFile();
             sf.index = index;
             sf.path = dlg.FileName;
             Thread g = new Thread(new ParameterizedThreadStart(GetFile)); //创建进程
             g.Start(sf);                                   //开始进程
             Parent.AcceptRecvFile(TalkUser.ip, id);
         }
         
     }
     //MessageBox.Show(id.ToString());
 }