Ejemplo n.º 1
0
        private void join_button_Click(object sender, EventArgs e)
        {
            TcpClient client = new TcpClient();

            try
            {
                client.Connect("127.0.0.1", PORT);
                ns          = client.GetStream();
                status.Text = "Connected";
                create_button.ButtonText = "CHOOSE FILE";
                join_button.Visible      = false;
                Task.Factory.StartNew(() => {
                    while (true)
                    {
                        if (ns.DataAvailable)
                        {
                            ShareFile.RecieveFile(ns);
                        }
                    }
                });
            }
            catch
            {
                status.Text = "Error connecting...";
            }
        }
Ejemplo n.º 2
0
 private void create_button_Click(object sender, EventArgs e)
 {
     if (((Bunifu.Framework.UI.BunifuThinButton2)sender).ButtonText == "CREATE")
     {
         try
         {
             if (Network.CreateConnection() == Network.Connection.Created)
             {
                 try
                 {
                     status.Text = "Waiting for connection";
                     listener    = TcpListener.Create(PORT);
                     listener.Start();
                     TcpClient client = listener.AcceptTcpClient();
                     ns          = client.GetStream();
                     status.Text = "Connected";
                     create_button.ButtonText = "CHOOSE FILE";
                     join_button.Visible      = false;
                     Task.Factory.StartNew(() => {
                         while (true)
                         {
                             if (ns.DataAvailable)
                             {
                                 ShareFile.RecieveFile(ns);
                             }
                         }
                     });
                 }
                 catch (Exception se)
                 {
                     MessageBox.Show(se.Message);
                 }
             }
         }
         catch (Exception conerror)
         {
             status.Text = conerror.Message;
         }
     }
     else if (((Bunifu.Framework.UI.BunifuThinButton2)sender).ButtonText == "CHOOSE FILE")
     {
         OpenFileDialog ofd = new OpenFileDialog();
         ofd.Title           = "Choose File";
         ofd.CheckFileExists = true;
         ofd.CheckPathExists = true;
         if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
         {
             ShareFile.SendFile(ns, ofd.FileName);
             ns.Flush();
         }
     }
 }