Beispiel #1
0
        private void ReceiveCallback(IAsyncResult AR)
        {
            try
            {
                int received = clientSocket.EndReceive(AR);

                if (received == 0)
                {
                    return;
                }

                Invoke((Action) delegate
                {
                    PersonPackage respuestaServer = new PersonPackage(buffer);
                    SubmitPersonToDataGrid(respuestaServer);
                });

                // Start receiving data again.
                clientSocket.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, ReceiveCallback, null);
            }
            // Avoid Pokemon exception handling in cases like these.
            catch (SocketException ex)
            {
                ShowErrorDialog(ex.Message);
            }
            catch (ObjectDisposedException ex)
            {
                ShowErrorDialog(ex.Message);
            }
        }
Beispiel #2
0
 private void SubmitPersonToDataGrid(PersonPackage person)
 {
     Invoke((Action) delegate
     {
         dataGridView.Rows.Add(person.User, person.Text);
     });
 }
Beispiel #3
0
 private void buttonSend_Click(object sender, EventArgs e)
 {
     try
     {
         // Serialize the textBoxes text before sending.
         PersonPackage person = new PersonPackage(checkBoxMale.Checked, (ushort)numberBoxAge.Value, textBoxEmployee.Text);
         byte[]        buffer = person.ToByteArray();
         clientSocket.BeginSend(buffer, 0, buffer.Length, SocketFlags.None, SendCallback, null);
     }
     catch (SocketException ex)
     {
         ShowErrorDialog(ex.Message);
         UpdateControlStates(false);
     }
     catch (ObjectDisposedException ex)
     {
         ShowErrorDialog(ex.Message);
         UpdateControlStates(false);
     }
 }
Beispiel #4
0
        private void buttonSend_Click(object sender, EventArgs e)
        {
            try
            {
                // Serialize the textBoxes text before sending.
                PersonPackage person = new PersonPackage(textBoxUser.Text, textBoxText.Text);
                byte[]        buffer = person.ToByteArray();

                SubmitPersonToDataGrid(person);

                clientSocket.BeginSend(buffer, 0, buffer.Length, SocketFlags.None, SendCallback, null);
            }
            catch (SocketException ex)
            {
                ShowErrorDialog(ex.Message);
                UpdateControlStates(false);
            }
            catch (ObjectDisposedException ex)
            {
                ShowErrorDialog(ex.Message);
                UpdateControlStates(false);
            }
        }