public ThreadListen(Socket temp,Socket Server,String username, Download down)
        {
            myDownload = down;
            this.S_server = Server;
            this.S_listen = temp;
            Username = username;
            myDownload = down;

            this.listenClient();
        }
 public ThreadDownload(String ip, String port, String sourse, String nameFile, Socket sockDownload,bool online,String username, String mePort, String meIp, int index,Download my)
 {
     C_online = online;
     IP_connect = ip;
     Port_connect = port;
     Str_sourse = sourse;
     Str_nameFile = nameFile;
     S_server = sockDownload;
     UserName = username;
     MePort = port;
     MeIP = ip;
     i_index = index;
     me = my;
     this.downloadFile();
 }
 public ThreadDownload(String ip, String port, String sourse, String nameFile, Socket sockDownload, bool online, String username, String mePort, String meIp, int index, Download my, DTOInfor data)
 {
     C_online = online;
     IP_connect = ip;
     Port_connect = port;
     Str_sourse = sourse;
     Str_nameFile = nameFile;
     S_server = sockDownload;
     UserName = username;
     MePort = port;
     MeIP = ip;
     i_index = index;
     me = my;
     DataInfor = data;
     me.Sema_addClient.Release();
     this.downloadFile();
 }
Exemple #4
0
        private void button1_Click_1(object sender, EventArgs e)
        {
            try
            {
                if (IP == null)
                {
                    IP = Dns.GetHostByName(Dns.GetHostName()).AddressList[0];
                }
                if (textBox1.Text == "" || textBox2.Text == "")
                {

                    MessageBox.Show("Username or Password incorrect !", "MessageBox Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button2);

                    return;
                }
                if (textBox5.Text == "" && checkBox2.Checked == false)
                {

                    MessageBox.Show("NumPort download incorrect !", "MessageBox Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button2);

                    return;
                }
                if ((textBox3.Text == "" || textBox4.Text == "") && checkBox1.Checked == false)
                {

                    MessageBox.Show("IP Address incorrect !", "MessageBox Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button2);

                    return;
                }
                //Input data IP and Port :
                String szPortDownload = textBox5.Text;
                if (checkBox2.Checked == true)
                {
                    szPortDownload = "9090";
                }
                else
                {
                    if (System.Convert.ToInt32(textBox5.Text, 10) < 65000)
                        szPortDownload = textBox5.Text;
                    else
                    {
                        MessageBox.Show("Port of Client between 0 and 65430");
                        return;
                    }
                }
                String szIPSelected = textBox3.Text;
                String szPort = textBox4.Text;
                if (checkBox1.Checked == true)
                {
                    szIPSelected = IP.ToString() ;
                    szPort = "8080";
                }
                int alPort = System.Convert.ToInt16(szPort, 10);

                //Create Socket :
                IPEndPoint ipep = new IPEndPoint(IPAddress.Parse(szIPSelected), Convert.ToInt32(szPort));
                S_Client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

                //Connect :
                S_Client.Connect(ipep);

                //Send information from Client :
                string MyLogin = "******" + textBox1.Text.Trim() + "@" + textBox2.Text + "@" + szPortDownload+"@"+IP.ToString()+"@null";
                byte[] byMyLogin = System.Text.Encoding.ASCII.GetBytes(MyLogin);
                this.S_Client.Send(byMyLogin);

                //doi ket qua tu server :
                S_Client.ReceiveTimeout = 5000;
                byte[] login = new byte[64];
                int i_login = this.S_Client.Receive(login);
                char[] chars_login = new char[i_login];
                System.Text.Decoder d_login = System.Text.Encoding.UTF8.GetDecoder();
                int charLen = d_login.GetChars(login, 0, i_login, chars_login, 0);
                System.String S_login = new System.String(chars_login);

                if (S_login == "Login")
                {
                    button1.Enabled = false;
                    this.Hide();

                    //Close va deface giao dien tai day :
                    Download myDownload = new Download(S_Client, textBox1.Text);
                    delPassData del = new delPassData(myDownload.funData);
                    del(this.textBox5);
                    myDownload.Text = textBox1.Text;
                    myDownload.IP = IP;
                    myDownload.ShowDialog();

                    this.Close();
                }
                else
                    MessageBox.Show("Error Login! Please try again!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (SocketException se)
            {
                MessageBox.Show(se.Message);
            }
        }
Exemple #5
0
        private void button1_Click_1(object sender, EventArgs e)
        {
            try
            {
                if (IP == null)
                {
                    IP = Dns.GetHostByName(Dns.GetHostName()).AddressList[0];
                }
                if (textBox1.Text == "" || textBox2.Text == "")
                {
                    MessageBox.Show("Username or Password incorrect !", "MessageBox Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button2);

                    return;
                }
                if (textBox5.Text == "" && checkBox2.Checked == false)
                {
                    MessageBox.Show("NumPort download incorrect !", "MessageBox Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button2);

                    return;
                }
                if ((textBox3.Text == "" || textBox4.Text == "") && checkBox1.Checked == false)
                {
                    MessageBox.Show("IP Address incorrect !", "MessageBox Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button2);

                    return;
                }
                //Input data IP and Port :
                String szPortDownload = textBox5.Text;
                if (checkBox2.Checked == true)
                {
                    szPortDownload = "9090";
                }
                else
                {
                    if (System.Convert.ToInt32(textBox5.Text, 10) < 65000)
                    {
                        szPortDownload = textBox5.Text;
                    }
                    else
                    {
                        MessageBox.Show("Port of Client between 0 and 65430");
                        return;
                    }
                }
                String szIPSelected = textBox3.Text;
                String szPort       = textBox4.Text;
                if (checkBox1.Checked == true)
                {
                    szIPSelected = IP.ToString();
                    szPort       = "8080";
                }
                int alPort = System.Convert.ToInt16(szPort, 10);

                //Create Socket :
                IPEndPoint ipep = new IPEndPoint(IPAddress.Parse(szIPSelected), Convert.ToInt32(szPort));
                S_Client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

                //Connect :
                S_Client.Connect(ipep);

                //Send information from Client :
                string MyLogin   = "******" + textBox1.Text.Trim() + "@" + textBox2.Text + "@" + szPortDownload + "@" + IP.ToString() + "@null";
                byte[] byMyLogin = System.Text.Encoding.ASCII.GetBytes(MyLogin);
                this.S_Client.Send(byMyLogin);

                //doi ket qua tu server :
                S_Client.ReceiveTimeout = 5000;
                byte[] login                = new byte[64];
                int    i_login              = this.S_Client.Receive(login);
                char[] chars_login          = new char[i_login];
                System.Text.Decoder d_login = System.Text.Encoding.UTF8.GetDecoder();
                int           charLen       = d_login.GetChars(login, 0, i_login, chars_login, 0);
                System.String S_login       = new System.String(chars_login);

                if (S_login == "Login")
                {
                    button1.Enabled = false;
                    this.Hide();

                    //Close va deface giao dien tai day :
                    Download    myDownload = new Download(S_Client, textBox1.Text);
                    delPassData del        = new delPassData(myDownload.funData);
                    del(this.textBox5);
                    myDownload.Text = textBox1.Text;
                    myDownload.IP   = IP;
                    myDownload.ShowDialog();

                    this.Close();
                }
                else
                {
                    MessageBox.Show("Error Login! Please try again!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (SocketException se)
            {
                MessageBox.Show(se.Message);
            }
        }