本文整理汇总了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);
}
示例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);
}
示例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);
}
示例4: Receive_internal
private static int Receive_internal (IntPtr sock,
WSABUF[] bufarray,
SocketFlags flags,
out int error)
{
throw new System.NotImplementedException();
}
示例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);
}
});
}
示例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;
}
示例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);
}
});
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
示例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();
}
示例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));
}
示例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);
}
}
示例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);
}