Exemplo n.º 1
0
        private void btnSend_Click(object sender, RoutedEventArgs e)
        {
            if (btnConnect.IsEnabled)
            {
                System.Windows.MessageBox.Show("Please connect to the local server!");
            }
            else if (listbox.SelectedIndex != -1)
            {
                if (txtMessage.Text.Length > 0 && !ifFileSelected && !txtMessage.Text.Equals(" ") && !txtMessage.Text.Equals("\n"))
                {
                    client.WriteLine(listbox.SelectedItem.ToString() + "#" + username + ": " + txtMessage.Text);
                }
                else if (ifFileSelected)
                {
                    byte[] b1 = File.ReadAllBytes(op.FileName);
                    client.Write(listbox.SelectedItem.ToString() + "#File#" + fi.Name + "#");
                    client.Write(b1);
                    ifFileSelected = false;
                }
                else
                {
                    System.Windows.MessageBox.Show("Please type something or choose a file to send!");
                }
            }
            else
            {
                System.Windows.MessageBox.Show("Please select someone to send the message to!");
            }

            txtMessage.Text = ""; //Empties the text message box
        }
Exemplo n.º 2
0
 //When connect button is pressed
 private void ConnectButton_Click(object sender, EventArgs e)
 {
     client.Connect(textHost.Text, Convert.ToInt32(textPort.Text));
     ConnectButton.Enabled = false;
     StatusText.Text       = "Connected!";
     client.WriteLine("\r\n" + NameTextBox.Text + " has connected");
     GameTextBox.Text = "Waiting for an opponent, please wait...\r\n";
 }
Exemplo n.º 3
0
 private void btnConnect_Click(object sender, EventArgs e)
 {
     btnConnect.Enabled = false;
     try
     {
         client.Connect(txtHost.Text, int.Parse(txtPort.Text));
         client.WriteLine("Client connected!");
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message.ToString());
         btnConnect.Enabled = true;
     }
 }
Exemplo n.º 4
0
        private void btnSend_Click(object sender, EventArgs e)
        {
            //   client.WriteLineAndGetReply(txtMessage.Text, TimeSpan.FromSeconds(3));

            client.WriteLine(txtMessage.Text);
        }