Exemple #1
0
        /// <summary>
        /// Writes raw message to the remote server.
        /// </summary>
        /// <param name="message">Message to send</param>
        protected void WriteMessage(string message)
        {
            lock (writeLocker)
            {
                if (Connected())
                {
                    try
                    {
                        apiWriteStream.WriteLine(message);
                        apiWriteStream.Flush();
                    }
                    catch (IOException ex)
                    {
                        Disconnect();
                        throw new APICommunicationException("Error while sending the data: " + ex.Message);
                    }
                }
                else
                {
                    Disconnect();
                    throw new APICommunicationException("Error while sending the data (socket disconnected)");
                }

                if (OnMessageSended != null)
                {
                    OnMessageSended.Invoke(message);
                }
            }
        }
 public void WriteMessage(string msg)
 {
     OnMessageSended?.Invoke(this, msg);
 }