Пример #1
0
        public IAsyncResult BeginSendMessage(string message, AsyncCallback asyncCallback, object state)
        {
            WriteSendBuffer(message);

            var asyncResult = new AsyncResultNoReturnValue(asyncCallback, state);

            socket.BeginSend(outputBuffer, sendBufferOffset, sendBufferSize - sendBufferOffset, SocketFlags.None, HandleSendCompleted, asyncResult);

            return asyncResult;
        }
        private IAsyncResult DoBeginSend(byte[] bytesToSend, AsyncCallback asyncCallback, object state)
        {
            if (asyncResult != null)
            {
                throw new InvalidOperationException("Can only send a server handshake once per " + GetType().Name + " instance");
            }

            asyncResult = new AsyncResultNoReturnValue(asyncCallback, state);

            sendBuffer = bytesToSend;
            socket.BeginSend(sendBuffer, 0, sendBuffer.Length, SocketFlags.None, HandleSendCompleted, null);

            return asyncResult;
        }