Exemple #1
0
        private void dataSender_DoWork(object sender, DoWorkEventArgs e)
        {
            if (client != null && client.Connected)
            {
                if (image_to_send != null)
                {
                    // Convert Image to bytes
                    byte[] imageBytes = CchatImage.GetByteArrayFromImage(image_to_send);
                    // Store length of the byte array of the Image
                    string imageLength = "" + imageBytes.Length;
                    // Send the length
                    streamWriter.WriteLine(imageLength);
                    // Send the Image
                    binaryWriter.Write(imageBytes, 0, imageBytes.Length);
                    // Show Image to self
                    PrintImage(image_to_send);
                    // Clean up old image to send
                    image_to_send = null;
                    // Wait before sending next
                    Thread.Sleep(1000);
                }

                if (text_to_send != null)
                {
                    // Send text written in the textbox
                    streamWriter.WriteLine(MSG_PREFIX_RECEIVER + text_to_send);
                    // Show text written to self
                    PrintText(MSG_PREFIX_SENDER + text_to_send);
                    // Store text written in textbox to log
                    CchatLog.WriteToLog(MSG_PREFIX_SENDER + text_to_send);
                    // Clean up old text to send
                    text_to_send = null;
                }
            }
            else
            {
                PrintText(MSG_ERROR_SEND_DATA);
                return;
            }
        }