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


C# SocketFlags类代码示例

本文整理汇总了C#中SocketFlags的典型用法代码示例。如果您正苦于以下问题:C# SocketFlags类的具体用法?C# SocketFlags怎么用?C# SocketFlags使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: Receive

        public static int Receive(this Socket socket, byte[] buffer, int offset, int size, int timeout, SocketFlags socketFlags)
        {
            if (!WaitForData(socket, timeout))
                return 0;

            return socket.Receive(buffer, offset, size, socketFlags);
        }
开发者ID:luhcmps,项目名称:LSCoder.Net.Ftp,代码行数:7,代码来源:SocketExtension.cs

示例2: ReceiveAsync

 public static Task<int> ReceiveAsync(
     this Socket socket, 
     IList<ArraySegment<byte>> buffers, 
     SocketFlags socketFlags)
 {
     return Task<int>.Factory.FromAsync(socket.BeginReceive, socket.EndReceive, buffers, socketFlags, null);
 }
开发者ID:JonHanna,项目名称:corefx,代码行数:7,代码来源:SocketTaskExtensions.cs

示例3: MultipleSend

		internal void MultipleSend (BufferOffsetSize[] buffers, SocketFlags socketFlags)
		{
			var segments = new ArraySegment<byte> [buffers.Length];
			for (int i = 0; i < buffers.Length; i++)
				segments [i] = new ArraySegment<byte> (buffers [i].Buffer, buffers [i].Offset, buffers [i].Size);
			Send (segments, socketFlags);
		}
开发者ID:Profit0004,项目名称:mono,代码行数:7,代码来源:Socket.cs

示例4: Receive_internal

		private static int Receive_internal (IntPtr sock,
		WSABUF[] bufarray,
		SocketFlags flags,
		out int error)
		{
			throw new System.NotImplementedException();
		}
开发者ID:desunit,项目名称:Mono-Class-Libraries,代码行数:7,代码来源:Socket.Mosa.cs

示例5: ToFrameClientObservable

        public static IObservable<DisposableByteBuffer> ToFrameClientObservable(this Socket socket, SocketFlags socketFlags, BufferManager bufferManager)
        {
            return Observable.Create<DisposableByteBuffer>(async (observer, token) =>
            {
                var headerBuffer = new byte[sizeof(int)];

                try
                {
                    while (!token.IsCancellationRequested)
                    {
                        if (await socket.ReceiveCompletelyAsync(headerBuffer, headerBuffer.Length, socketFlags, token) != headerBuffer.Length)
                            break;
                        var length = BitConverter.ToInt32(headerBuffer, 0);

                        var buffer = bufferManager.TakeBuffer(length);
                        if (await socket.ReceiveCompletelyAsync(buffer, length, socketFlags, token) != length)
                            break;

                        observer.OnNext(new DisposableByteBuffer(buffer, length, Disposable.Create(() => bufferManager.ReturnBuffer(buffer))));
                    }

                    observer.OnCompleted();

                    socket.Close();
                }
                catch (Exception error)
                {
                    observer.OnError(error);
                }
            });
        }
开发者ID:tleviathan,项目名称:JetBlack.Network,代码行数:31,代码来源:FrameClientExtensions.cs

示例6: ReceiveAsync

        /// <summary>
        /// Asynchronously receives data from a connected socket.
        /// </summary>
        /// <param name="socket">
        /// The socket from which to read data.
        /// </param>
        /// <param name="buffer">
        /// An array of type <see cref="byte"/> that is the storage location for
        /// the received data.
        /// </param>
        /// <param name="offset">
        /// The zero-based position in the <paramref name="buffer"/> parameter at which to
        /// start storing data.
        /// </param>
        /// <param name="size">
        /// The number of bytes to receive.
        /// </param>
        /// <param name="socketFlags">
        /// A bitwise combination of the <see cref="SocketFlags"/> values.
        /// </param>
        /// <returns>
        /// The number of bytes received.
        /// </returns>
        public static Task<int> ReceiveAsync(
            this Socket socket,
            byte[] buffer,
            int offset,
            int size,
            SocketFlags socketFlags)
        {
            var tcs = new TaskCompletionSource<int>(socket);

            socket.BeginReceive(
                buffer,
                offset,
                size,
                socketFlags,
                iar =>
                {
                    var t = (TaskCompletionSource<int>)iar.AsyncState;
                    var s = (Socket)t.Task.AsyncState;
                    try
                    {
                        t.TrySetResult(s.EndReceive(iar));
                    }
                    catch (Exception ex)
                    {
                        t.TrySetException(ex);
                    }
                },
                tcs);

            return tcs.Task;
        }
开发者ID:vebin,项目名称:madb,代码行数:54,代码来源:SocketExtensions.cs

示例7: ToClientObservable

        public static IObservable<ByteBuffer> ToClientObservable(this Socket socket, int size, SocketFlags socketFlags)
        {
            return Observable.Create<ByteBuffer>(async (observer, token) =>
            {
                var buffer = new byte[size];

                try
                {
                    while (!token.IsCancellationRequested)
                    {
                        var received = await socket.ReceiveAsync(buffer, 0, size, socketFlags);
                        if (received == 0)
                            break;

                        observer.OnNext(new ByteBuffer(buffer, received));
                    }

                    observer.OnCompleted();
                }
                catch (Exception error)
                {
                    observer.OnError(error);
                }
            });
        }
开发者ID:tleviathan,项目名称:JetBlack.Network,代码行数:25,代码来源:ClientExtensions.cs

示例8: Init

		public void Init (Socket socket, AsyncCallback callback, object state, SocketOperation operation)
		{
			base.Init (callback, state);

			this.socket = socket;
			this.handle = socket != null ? socket.Handle : IntPtr.Zero;
			this.operation = operation;

			DelayedException = null;

			EndPoint = null;
			Buffer = null;
			Offset = 0;
			Size = 0;
			SockFlags = SocketFlags.None;
			AcceptSocket = null;
			Addresses = null;
			Port = 0;
			Buffers = null;
			ReuseSocket = false;
			CurrentAddress = 0;

			AcceptedSocket = null;
			Total = 0;

			error = 0;

			EndCalled = 0;
		}
开发者ID:nickolyamba,项目名称:mono,代码行数:29,代码来源:SocketAsyncResult.cs

示例9: BeginMultipleSend

		internal IAsyncResult BeginMultipleSend (BufferOffsetSize[] buffers, SocketFlags socketFlags, AsyncCallback callback, object state)
		{
			var segments = new ArraySegment<byte> [buffers.Length];
			for (int i = 0; i < buffers.Length; i++)
				segments [i] = new ArraySegment<byte> (buffers [i].Buffer, buffers [i].Offset, buffers [i].Size);
			return BeginSend (segments, socketFlags, callback, state);
		}
开发者ID:Profit0004,项目名称:mono,代码行数:7,代码来源:Socket.cs

示例10: BeginReceive

 public IAsyncResult BeginReceive(IList<ArraySegment<byte>> buffers, SocketFlags socketFlags, AsyncCallback callback, object state)
 {
     Encoding.UTF8.GetBytes(_request).CopyTo(buffers[0].Array, 0);
     var result = new Mock<IAsyncResult>();
     result.Setup(r => r.AsyncState).Returns(state);
     callback(result.Object);
     return result.Object;
 }
开发者ID:emiaj,项目名称:Fleck,代码行数:8,代码来源:HandshakeHandlerTests.cs

示例11: CrosReceive

 /// <summary>
 /// Receives data from connected <see cref="CrosSocket"/> and stores it into the buffer using specified <see cref="SocketFlags"/>, buffer is resized to data received
 /// </summary>
 /// <param name="buffer">Array which will contain received data</param>
 /// <param name="socketFlags">SocketFlags to use</param>
 /// <returns>Number of bytes received</returns>
 public virtual int CrosReceive(ref byte[] buffer, SocketFlags socketFlags)
 {
     byte[] lengthBytes = new byte[4];
     base.Receive(lengthBytes, socketFlags);
     int dataSize = BitConverter.ToInt32(lengthBytes, 0);
     Array.Resize(ref buffer, dataSize);
     return base.Receive(buffer, socketFlags);
 }
开发者ID:rubendal,项目名称:CrosSocket,代码行数:14,代码来源:CrosSocket.cs

示例12: Send_internal

		private static int Send_internal(IntPtr sock,
		byte[] buf, int offset,
		int count,
		SocketFlags flags,
		out int error)
		{
			throw new System.NotImplementedException();
		}
开发者ID:desunit,项目名称:Mono-Class-Libraries,代码行数:8,代码来源:Socket_2_1.Mosa.cs

示例13: UDPClient

        /// <summary>
        /// Initializes a new instance of the <see cref="UDPClient"/> class.
        /// </summary>
        /// <param name="ep">The ep.</param>
        public UDPClient(IPAddress IPAddress, UInt16 Port, Boolean Broadcast = false, SocketFlags Socketflags = SocketFlags.None)
            : this(Broadcast, Socketflags)
        {
            this.InternalIPAddress  = IPAddress;
            this.InternalPort       = Port;

            InternalSocket.Connect(new IPEndPoint(IPAddress, Port));
        }
开发者ID:Vanaheimr,项目名称:Nyi,代码行数:12,代码来源:UDPClient.cs

示例14: Send

 public int Send(byte[] data, int offset, int length, SocketFlags flags) {
     lock (this) {
         if (_shuttedDown_Send)
             return 0;
         else
             return _socket.Send(data, offset, length, flags);
     }
 }
开发者ID:Ricordanza,项目名称:poderosa,代码行数:8,代码来源:channel.cs

示例15: SendToAsync

 /// <summary>
 /// Sends data asynchronously to a specific remote host
 /// </summary>
 /// <param name="socket">socket</param>
 /// <param name="buffer">an array of type System.Byte that contains the data to send</param>
 /// <param name="offset">the zero-based position in buffer at which to begin sending data</param>
 /// <param name="size">the number of bytes to send</param>
 /// <param name="flags">a bitwise combination of the System.Net.Sockets.SocketFlags values.</param>
 /// <param name="remoteEP">an System.Net.EndPoint that represents the remote device</param>
 /// <returns>Task</returns>
 public static Task SendToAsync(this Socket socket, byte[] buffer, int offset, int size, SocketFlags flags, EndPoint remoteEP)
 {
     return Task<int>.Factory.FromAsync(
         (ac, state) => socket.BeginSendTo(buffer, offset, size, flags, remoteEP, ac, state),
         socket.EndSendTo,
         null,
         TaskCreationOptions.None);
 }
开发者ID:kakone,项目名称:SSDP.Portable,代码行数:18,代码来源:SocketExtensions.cs


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