示例#1
0
        // Send a File to the Server!
        private void buttonSendFile_Click(object sender, EventArgs e)
        {
            try
            {
                IPAddress ipadd;
                if (IPAddress.TryParse(textIp.Text, out ipadd))
                {
                    _ipaddress = textIp.Text;
                    _portnumber = uint.Parse(textPort.Text);
                    ClientSocket c = new ClientSocket(_ipaddress, _portnumber);

                    if(_file.Length == 0)
                    {
                        MessageBox.Show("Please select a file to send first");
                        return;
                    }

                    c.SendFile(_directory + "\\" + _file, _file);

                }
                else
                    MessageBox.Show("Not a valid IP Address");

                MessageBox.Show("File has been sent to the server", "Success", MessageBoxButtons.OK);
            }
            catch (System.FormatException ex)
            {
                MessageBox.Show("Not a valid Port Number", ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Send Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }