コード例 #1
0
 private void OnSocketRequestAsync(SocketRequestEventArg e)
 {
     var handler = this.SocketRequest;
     if (handler != null)
     {
         handler.BeginInvoke(this,
                             e,
                             handler.EndInvoke,
                             null);
     }
 }
コード例 #2
0
        /// <remarks>This code does sending specifically for the <paramref name="controlComplexSocket" /> and does some logging</remarks>
        private async Task<bool> SendAndLogAsync(ComplexSocket controlComplexSocket,
                                                 CancellationToken cancellationToken,
                                                 string command,
                                                 params object[] args)
        {
            command = string.Format(command,
                                    args);
            if (!command.EndsWith(Environment.NewLine))
            {
                command = string.Concat(command,
                                        Environment.NewLine);
            }

            {
                var socketRequestEventArg = new SocketRequestEventArg(command);
                this.OnSocketRequestAsync(socketRequestEventArg);
            }

            {
                var buffer = this.Encoding.GetBytes(command);
                using (var memoryStream = new MemoryStream(buffer))
                {
                    var success = await controlComplexSocket.Socket.SendAsync(this.ChunkSendBufferSize,
                                                                              controlComplexSocket.GetSocketAsyncEventArgs,
                                                                              memoryStream,
                                                                              cancellationToken);
                    return success;
                }
            }
        }