예제 #1
0
        public void SendMessage(string message)
        {
            try
            {
                // Create the message to send
                StringMessage msg = new StringMessage
                {
                    Message = message
                };

                // Serialize the message to a binary array
                byte[] binaryMessage = SerializationHelper.Serialize(msg);

                // Send the message; the state is used by ClientSocket_WriteCompleted to display an output to the log
                string description = "<string message: " + msg.Message + ">";
                ClientSocket.WriteAsync(binaryMessage, description);

                Console.WriteLine("Sending message " + description);
            }
            catch (Exception ex)
            {
                ResetSocket();
                Console.WriteLine("Error sending message to socket: [" + ex.GetType().Name + "] " + ex.Message);
            }
            finally
            {
                RefreshDisplay();
            }
        }
예제 #2
0
        private void buttonSendMessage_Click(object sender, EventArgs e)
        {
            try
            {
                // Create the message to send
                Messages.StringMessage message = new Messages.StringMessage();
                message.Message = textBoxMessage.Text;

                // Serialize the message to a binary array
                byte[] binaryMessage = Messages.Util.Serialize(message);

                // Send the message; the state is used by ClientSocket_WriteCompleted to display an output to the log
                string description = "<string message: " + message.Message + ">";
                ClientSocket.WriteAsync(binaryMessage, description);

                textBoxLog.AppendText("Sending message " + description + Environment.NewLine);
            }
            catch (Exception ex)
            {
                ResetSocket();
                textBoxLog.AppendText("Error sending message to socket: [" + ex.GetType().Name + "] " + ex.Message + Environment.NewLine);
            }
            finally
            {
                RefreshDisplay();
            }
        }