Пример #1
0
        void OnSendDone(IAsyncResult ar)
        {
            SendObject sobj = (SendObject)ar.AsyncState;
            Socket     s    = sobj.Socket;

            s.EndSend(ar);
            sobj.OnSendDone?.Invoke();
        }
Пример #2
0
        /// <summary>
        /// Send a message/command to the server
        /// </summary>
        /// <param name="message">The message that needs to get sent</param>
        /// <param name="onSendDone">This will be executed when the message has been sent</param>
        public void Send(string message, Action onSendDone)
        {
            // If the message already contains <EOF> then remove it.
            if (message.Contains("<EOF>"))
            {
                message = message.Replace("<EOF>", "");
            }

            byte[] data = Encoding.ASCII.GetBytes(message + "<EOF>");

            SendObject sendObject = new SendObject()
            {
                Socket     = m_Client,
                OnSendDone = onSendDone
            };

            m_Client.BeginSend(data, 0, data.Length, 0, OnSendDone, sendObject);
        }