14 private readonly
byte[]
_buffer =
new byte[65536];
56 _clientSocket.Ttl =
value;
68 _clientSocket.DontFragment =
value;
80 _clientSocket.MulticastLoopback =
value;
92 _clientSocket.EnableBroadcast =
value;
104 _clientSocket.ExclusiveAddressUse =
value;
155 [SupportedOSPlatform(
"windows")]
183 protected virtual void Dispose(
bool disposing)
196 if (clientSocket !=
null)
238 if (endPoint ==
null)
259 if (datagram ==
null)
267 if (
_active && endPoint !=
null)
275 if (
_active && (hostname !=
null || port != 0))
280 if (hostname !=
null && port != 0)
287 if (hostAddresses.Length == 0 || i == hostAddresses.Length)
292 result =
new IPEndPoint(hostAddresses[i], port);
312 byte[]
array =
new byte[num];
322 if (multicastAddr ==
null)
356 if (multicastAddr ==
null)
375 if (multicastAddr ==
null)
390 if (multicastAddr ==
null)
413 if (multicastAddr ==
null)
452 if (endPoint ==
null)
463 if (endPoint ==
null)
506 if (hostname ==
null)
522 public void Connect(
string hostname,
int port)
525 if (hostname ==
null)
559 socket2.
Connect(iPAddress, port);
563 else if (socket !=
null)
565 socket.
Connect(iPAddress, port);
631 if (endPoint ==
null)
636 Client.Connect(endPoint);
648 byte[]
array =
new byte[num];
662 if (
_active && endPoint !=
null)
666 if (endPoint ==
null)
677 if (
_active && endPoint !=
null)
681 if (endPoint ==
null)
686 return Client.SendTo(datagram,
SocketFlags.None, endPoint);
689 public int Send(
byte[] dgram,
int bytes,
string? hostname,
int port)
727 ThrowObjectDisposedException();
729 void ThrowObjectDisposedException()
static void BlockCopy(Array src, int srcOffset, Array dst, int dstOffset, int count)
static void SuppressFinalize(object obj)
static IPAddress[] GetHostAddresses(string hostNameOrAddress)
static bool IsFatal(Exception exception)
static readonly IPAddress Broadcast
override bool Equals([NotNullWhen(true)] object? comparand)
static readonly IPAddress Any
static readonly IPAddress IPv6Any
AddressFamily AddressFamily
static readonly IPEndPoint Any
static readonly IPEndPoint IPv6Any
override AddressFamily AddressFamily
static readonly System.Net.NetEventSource Log
static void Info(object thisOrContextObject, FormattableString formattableString=null, [CallerMemberName] string memberName=null)
static bool ValidateRange(int actual, int fromAllowed, int toAllowed)
static bool OSSupportsIPv6
int EndSendTo(IAsyncResult asyncResult)
bool ReceiveFromAsync(SocketAsyncEventArgs e)
int EndReceiveFrom(IAsyncResult asyncResult, ref EndPoint endPoint)
IAsyncResult BeginReceiveFrom(byte[] buffer, int offset, int size, SocketFlags socketFlags, ref EndPoint remoteEP, AsyncCallback? callback, object? state)
virtual void Dispose(bool disposing)
static bool OSSupportsIPv4
bool SendAsync(SocketAsyncEventArgs e)
int EndSend(IAsyncResult asyncResult)
void Bind(EndPoint localEP)
void Connect(EndPoint remoteEP)
void SetIPProtectionLevel(IPProtectionLevel level)
void InternalShutdown(SocketShutdown how)
bool SendToAsync(SocketAsyncEventArgs e)
IAsyncResult BeginSendTo(byte[] buffer, int offset, int size, SocketFlags socketFlags, EndPoint remoteEP, AsyncCallback? callback, object? state)
IAsyncResult BeginSend(byte[] buffer, int offset, int size, SocketFlags socketFlags, AsyncCallback? callback, object? state)
void SetSocketOption(SocketOptionLevel optionLevel, SocketOptionName optionName, int optionValue)
UdpClient(string hostname, int port)
void CheckForBroadcast(IPAddress ipAddress)
int Send(byte[] dgram, int bytes, string? hostname, int port)
void CreateClientSocket()
IAsyncResult BeginSend(byte[] datagram, int bytes, string? hostname, int port, AsyncCallback? requestCallback, object? state)
bool IsAddressFamilyCompatible(AddressFamily family)
UdpClient(IPEndPoint localEP)
Task< int > SendAsync(byte[] datagram, int bytes, string? hostname, int port)
ValueTask< int > SendAsync(ReadOnlyMemory< byte > datagram, IPEndPoint? endPoint, CancellationToken cancellationToken=default(CancellationToken))
void Connect(IPAddress addr, int port)
Task< int > SendAsync(byte[] datagram, int bytes)
IAsyncResult BeginSend(byte[] datagram, int bytes, IPEndPoint? endPoint, AsyncCallback? requestCallback, object? state)
int EndSend(IAsyncResult asyncResult)
ValueTask< int > SendAsync(ReadOnlyMemory< byte > datagram, CancellationToken cancellationToken=default(CancellationToken))
int Send(ReadOnlySpan< byte > datagram, IPEndPoint? endPoint)
IPEndPoint GetEndpoint(string hostname, int port)
byte[] EndReceive(IAsyncResult asyncResult, ref IPEndPoint? remoteEP)
int Send(byte[] dgram, int bytes, IPEndPoint? endPoint)
void DropMulticastGroup(IPAddress multicastAddr, int ifindex)
void Connect(string hostname, int port)
int Send(byte[] dgram, int bytes)
UdpClient(int port, AddressFamily family)
bool IsBroadcast(IPAddress address)
void JoinMulticastGroup(IPAddress multicastAddr, IPAddress localAddress)
Task< UdpReceiveResult > ReceiveAsync()
Task< int > SendAsync(byte[] datagram, int bytes, IPEndPoint? endPoint)
ValueTask< int > SendAsync(ReadOnlyMemory< byte > datagram, string? hostname, int port, CancellationToken cancellationToken=default(CancellationToken))
int Send(ReadOnlySpan< byte > datagram)
void AllowNatTraversal(bool allowed)
void DropMulticastGroup(IPAddress multicastAddr)
void JoinMulticastGroup(IPAddress multicastAddr)
IAsyncResult BeginSend(byte[] datagram, int bytes, AsyncCallback? requestCallback, object? state)
UdpClient(AddressFamily family)
ValueTask< UdpReceiveResult > ReceiveAsync(CancellationToken cancellationToken)
void ValidateDatagram(byte[] datagram, int bytes, IPEndPoint endPoint)
void Connect(IPEndPoint endPoint)
void JoinMulticastGroup(int ifindex, IPAddress multicastAddr)
int Send(ReadOnlySpan< byte > datagram, string? hostname, int port)
IAsyncResult BeginReceive(AsyncCallback? requestCallback, object? state)
void JoinMulticastGroup(IPAddress multicastAddr, int timeToLive)
byte[] Receive([NotNull] ref IPEndPoint? remoteEP)
virtual void Dispose(bool disposing)
static bool ValidatePortNumber(int port)
static string net_protocol_invalid_family
static string net_invalidAddressList
static string net_udpconnected
static string Format(string resourceFormat, object p1)
static string net_protocol_invalid_multicast_family
static string net_value_cannot_be_negative
static string net_notconnected