当前位置: 首页>>代码示例>>C#>>正文


C# this.BeginSend方法代码示例

本文整理汇总了C#中this.BeginSend方法的典型用法代码示例。如果您正苦于以下问题:C# this.BeginSend方法的具体用法?C# this.BeginSend怎么用?C# this.BeginSend使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在this的用法示例。


在下文中一共展示了this.BeginSend方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SendAsync

        public static Task SendAsync(this Socket socket, byte[] buffer, int offset, int size, SocketFlags flags = SocketFlags.None)
        {
            if (socket == null) throw new ArgumentNullException("socket");
            if (buffer == null) throw new ArgumentNullException("buffer");

            return Task<int>.Factory.FromAsync(
                (ac, state) => socket.BeginSend(buffer, offset, size, flags, ac, state),
                socket.EndSend,
                null,
                TaskCreationOptions.None);
        }
开发者ID:JeffreySu,项目名称:MemcachedSharp,代码行数:11,代码来源:SocketExtensions.cs

示例2: SendAsyncTask

 public static Task SendAsyncTask(this Socket socket, byte[] dataToSend, CancellationTokenSource cancellationTokenSource)
 {
     return Task.Factory.FromAsync(
         (ac, o) => socket.BeginSend(dataToSend, 0, dataToSend.Length, SocketFlags.None, ac, null),
         ar =>
         {
             cancellationTokenSource.Token.ThrowIfCancellationRequested();
             socket.EndSend(ar);
         },
         null);
 }
开发者ID:gobixm,项目名称:learn,代码行数:11,代码来源:SocketExtensions.cs

示例3: SendAsync

 public static Task SendAsync(this Socket socket, byte[] buffer, int offset, int count, SocketFlags socketFlags)
 {
     var tcs = new TaskCompletionSource<int>(socket);
     socket.BeginSend(buffer, offset, count, socketFlags, iar =>
     {
         var t = (TaskCompletionSource<int>)iar.AsyncState;
         var s = (Socket)t.Task.AsyncState;
         try { t.TrySetResult(s.EndSend(iar)); }
         catch (Exception exc) { t.TrySetException(exc); }
     }, tcs);
     return tcs.Task;
 }
开发者ID:aluitink,项目名称:bifrost,代码行数:12,代码来源:SocketExtensions.cs

示例4: SendAsync

		public static Task<int> SendAsync(this Socket socket, byte[] buffer, int offset, int size, SocketFlags flags, out SocketError error) {
			var tsc = new TaskCompletionSource<int> ();

			socket.BeginSend (buffer, offset, size, flags, out error, asyncResult => {
				try {
					tsc.SetResult (socket.EndSend (asyncResult));
				} catch (Exception e) {
					tsc.SetException (e);
				}
			}, null);

			return tsc.Task;
		}
开发者ID:rbarinov,项目名称:imap-gmail-nokia-e71-fix,代码行数:13,代码来源:Program.cs

示例5: SendAsync

        public static Task<int> SendAsync(this Socket socket,
            byte[] buffer, int offset, int size, SocketFlags socketFlags)
        {
            if (socket == null) throw new ArgumentNullException(nameof(socket));

            var tcs = new TaskCompletionSource<int>();
            socket.BeginSend(buffer, offset, size, socketFlags, ar =>
            {
                try { tcs.TrySetResult(socket.EndReceive(ar)); }
                catch (Exception e) { tcs.TrySetException(e);  }
            }, state: null);
            return tcs.Task;
        }
开发者ID:buddalasunil999,项目名称:RserveCLI2,代码行数:13,代码来源:SocketExtensions.cs

示例6: AsyncSend

 public static Future<Packet> AsyncSend(
     this Session session, Packet packet
 )
 {
     var f = new Future<Packet>();
     session.BeginSend(packet, (_) => {
         try {
             f.Complete(session.EndSend(_));
         } catch (Exception ex) {
             f.Fail(ex);
         }
     });
     return f;
 }
开发者ID:kg,项目名称:shootbluesscripts,代码行数:14,代码来源:JabberExtensions.cs

示例7: SendAsync

        internal static Task<int> SendAsync(this Socket s, byte[] buffer, int offset, int count)
        {
            var tcs = new TaskCompletionSource<int>();

            s.BeginSend(buffer, offset, count, SocketFlags.None, iasr =>
            {
                try
                {
                    tcs.SetResult(s.EndSend(iasr));
                }
                catch (Exception e)
                {
                    tcs.SetException(e);
                }
            }, null);

            return tcs.Task;
        }
开发者ID:chakrit,项目名称:kayak,代码行数:18,代码来源:IO.cs

示例8: SendAsync

        public static Task<int> SendAsync(this Socket socket,
                                          byte[] buffer,
                                          int offset = 0,
                                          int size = 0,
                                          SocketFlags socketFlags = SocketFlags.None) {
            if(size <= 0)
                size = buffer.Length;

            var tcs = new TaskCompletionSource<int>();
            socket.BeginSend(buffer, offset, size, socketFlags,
                             iar => {
                                 try {
                                     tcs.TrySetResult(socket.EndSend(iar));
                                 }
                                 catch(Exception ex) {
                                     tcs.TrySetException(ex);
                                 }
                             }, null);

            return tcs.Task;
        }
开发者ID:debop,项目名称:NFramework,代码行数:21,代码来源:SocketAsync.cs

示例9: SendBytesAsync

 public static void SendBytesAsync(this Socket socket, byte[] bytes, int offset, int count, Action<bool> callback)
 {
     if (!MiscHelpers.Try(() => socket.BeginSend(bytes, offset, count, SocketFlags.None, result => socket.OnBytesSent(result, bytes, offset, count, callback), null)))
     {
         callback(false);
     }
 }
开发者ID:dirkelfman,项目名称:ClearScript,代码行数:7,代码来源:SocketHelpers.cs

示例10: AsyncSend

 public static void AsyncSend(this Socket socket, byte[] buffer)
 {
     socket.BeginSend(buffer, 0, buffer.Length, 0, new AsyncCallback(SendCallback), new State() { Socket = socket, Callback = null });
 }
开发者ID:viktorblondal,项目名称:Nugget,代码行数:4,代码来源:SocketExtension.cs

示例11: BeginSend

 /// <summary>
 /// BeginSend
 /// </summary>
 /// <param name="socket"></param>
 /// <param name="content"></param>
 /// <param name="asyncCallback"></param>
 /// <returns></returns>
 public static IAsyncResult BeginSend(this Socket socket, byte[] content, AsyncCallback asyncCallback) => socket.BeginSend(content, asyncCallback, null);
开发者ID:sdzxwxlsj,项目名称:lsjutil,代码行数:8,代码来源:TcpSocket.cs

示例12: SendNonBlocking

        public static Task<Either<int, SocketError>> SendNonBlocking(this Socket s, ArraySegment<byte> buf, SocketFlags flags)
        {
            SocketError err;

            var tcs = new TaskCompletionSource<Either<int, SocketError>>();

            try
            {
                IAsyncResult r = s.BeginSend(buf.Array, buf.Offset, buf.Count, flags, out err, iar =>
                {
                    try
                    {
                        SocketError errInner;
                        int n = s.EndSend(iar, out errInner);
                        if (n <= 0)
                            tcs.SetResult(errInner);
                        else
                            tcs.SetResult(n);
                    }
                    catch (SocketException skex)
                    {
                        tcs.SetResult(skex.SocketErrorCode);
                    }
                    catch (Exception ex)
                    {
                        tcs.SetException(ex);
                    }
                }, (object)null);

                if (r == null)
                    tcs.SetResult(err);
            }
            catch (SocketException skex)
            {
                tcs.SetResult(skex.SocketErrorCode);
            }
            catch (Exception ex)
            {
                tcs.SetException(ex);
            }

            return tcs.Task;
        }
开发者ID:JamesDunne,项目名称:lancaster-pgm,代码行数:43,代码来源:ExtensionMethods.cs

示例13: SendAsync

        public static Task<int> SendAsync(this Socket socket, byte[] buffer,
                                          int offset = 0, int size = -1,
                                          SocketFlags flags = SocketFlags.None)
        {
            if (size < 0)
                size = buffer.Length;

            var source = new TaskCompletionSource<int>(socket);
            socket.BeginSend(buffer, offset, size, flags, state =>
                {
                    try
                    {
                        source.SetResult(socket.EndSend(state));
                    }
                    catch (Exception e)
                    {
                        source.SetException(e);
                    }
                }, source);
            return source.Task;
        }
开发者ID:ktj007,项目名称:Lz,代码行数:21,代码来源:AsyncSocketExtension.cs

示例14: SendAPM

 public static void SendAPM(this Socket socket, byte[] buffer, int offset, int count, SocketFlags flags, Action<int> handler)
 {
     var callback = new AsyncCallback(asyncResult => handler(((Socket)asyncResult.AsyncState).EndSend(asyncResult)));
     socket.BeginSend(buffer, offset, count, flags, callback, socket);
 }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:5,代码来源:SocketAPMExtensions.cs

示例15: BeginSend

        /// <summary>
        /// Extends BeginSend so that when a state object is not needed, null does not need to be passed.
        /// <example>
        /// socket.BeginSend(buffers, socketFlags, errorCode, callback);
        /// </example>
        /// </summary>
        public static IAsyncResult BeginSend(this Socket socket, System.Collections.Generic.IList<ArraySegment<Byte>> buffers, SocketFlags socketFlags, out SocketError errorCode, AsyncCallback callback)
        {
            if(socket == null) throw new ArgumentNullException("socket");

            return socket.BeginSend(buffers, socketFlags, out errorCode, callback, null);
        }
开发者ID:peteraritchie,项目名称:ProductivityExtensions,代码行数:12,代码来源:Socketable.g.cs


注:本文中的this.BeginSend方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。