Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
UdpClient.cs
Go to the documentation of this file.
5
6namespace System.Net.Sockets;
7
8public class UdpClient : IDisposable
9{
11
12 private bool _active;
13
14 private readonly byte[] _buffer = new byte[65536];
15
16 private AddressFamily _family = AddressFamily.InterNetwork;
17
18 private bool _disposed;
19
20 private bool _isBroadcast;
21
22 protected bool Active
23 {
24 get
25 {
26 return _active;
27 }
28 set
29 {
30 _active = value;
31 }
32 }
33
35
36 public Socket Client
37 {
38 get
39 {
40 return _clientSocket;
41 }
42 set
43 {
45 }
46 }
47
48 public short Ttl
49 {
50 get
51 {
52 return _clientSocket.Ttl;
53 }
54 set
55 {
56 _clientSocket.Ttl = value;
57 }
58 }
59
60 public bool DontFragment
61 {
62 get
63 {
65 }
66 set
67 {
68 _clientSocket.DontFragment = value;
69 }
70 }
71
73 {
74 get
75 {
77 }
78 set
79 {
80 _clientSocket.MulticastLoopback = value;
81 }
82 }
83
84 public bool EnableBroadcast
85 {
86 get
87 {
89 }
90 set
91 {
92 _clientSocket.EnableBroadcast = value;
93 }
94 }
95
97 {
98 get
99 {
101 }
102 set
103 {
104 _clientSocket.ExclusiveAddressUse = value;
105 }
106 }
107
108 public UdpClient()
110 {
111 }
112
114 {
115 if (family != AddressFamily.InterNetwork && family != AddressFamily.InterNetworkV6)
116 {
118 }
119 _family = family;
121 }
122
123 public UdpClient(int port)
124 : this(port, AddressFamily.InterNetwork)
125 {
126 }
127
128 public UdpClient(int port, AddressFamily family)
129 {
131 {
132 throw new ArgumentOutOfRangeException("port");
133 }
134 if (family != AddressFamily.InterNetwork && family != AddressFamily.InterNetworkV6)
135 {
137 }
138 _family = family;
139 IPEndPoint localEP = ((_family != AddressFamily.InterNetwork) ? new IPEndPoint(IPAddress.IPv6Any, port) : new IPEndPoint(IPAddress.Any, port));
141 _clientSocket.Bind(localEP);
142 }
143
144 public UdpClient(IPEndPoint localEP)
145 {
146 if (localEP == null)
147 {
148 throw new ArgumentNullException("localEP");
149 }
150 _family = localEP.AddressFamily;
152 _clientSocket.Bind(localEP);
153 }
154
155 [SupportedOSPlatform("windows")]
156 public void AllowNatTraversal(bool allowed)
157 {
158 _clientSocket.SetIPProtectionLevel(allowed ? IPProtectionLevel.Unrestricted : IPProtectionLevel.EdgeRestricted);
159 }
160
162 {
163 if (family == _family)
164 {
165 return true;
166 }
167 if (family == AddressFamily.InterNetwork)
168 {
169 if (_family == AddressFamily.InterNetworkV6)
170 {
171 return _clientSocket.DualMode;
172 }
173 return false;
174 }
175 return false;
176 }
177
178 public void Dispose()
179 {
180 Dispose(disposing: true);
181 }
182
183 protected virtual void Dispose(bool disposing)
184 {
185 if (!disposing)
186 {
187 return;
188 }
189 if (System.Net.NetEventSource.Log.IsEnabled())
190 {
191 System.Net.NetEventSource.Info(this, null, "Dispose");
192 }
193 if (!_disposed)
194 {
195 Socket clientSocket = _clientSocket;
196 if (clientSocket != null)
197 {
198 clientSocket.InternalShutdown(SocketShutdown.Both);
199 clientSocket.Dispose();
200 _clientSocket = null;
201 }
202 _disposed = true;
203 GC.SuppressFinalize(this);
204 }
205 }
206
207 private void CheckForBroadcast(IPAddress ipAddress)
208 {
209 if (_clientSocket != null && !_isBroadcast && IsBroadcast(ipAddress))
210 {
211 _isBroadcast = true;
213 }
214 }
215
216 private bool IsBroadcast(IPAddress address)
217 {
218 if (address.AddressFamily == AddressFamily.InterNetworkV6)
219 {
220 return false;
221 }
222 return address.Equals(IPAddress.Broadcast);
223 }
224
225 public IAsyncResult BeginSend(byte[] datagram, int bytes, AsyncCallback? requestCallback, object? state)
226 {
227 return BeginSend(datagram, bytes, null, requestCallback, state);
228 }
229
230 public IAsyncResult BeginSend(byte[] datagram, int bytes, string? hostname, int port, AsyncCallback? requestCallback, object? state)
231 {
232 return BeginSend(datagram, bytes, GetEndpoint(hostname, port), requestCallback, state);
233 }
234
235 public IAsyncResult BeginSend(byte[] datagram, int bytes, IPEndPoint? endPoint, AsyncCallback? requestCallback, object? state)
236 {
237 ValidateDatagram(datagram, bytes, endPoint);
238 if (endPoint == null)
239 {
240 return _clientSocket.BeginSend(datagram, 0, bytes, SocketFlags.None, requestCallback, state);
241 }
242 CheckForBroadcast(endPoint.Address);
243 return _clientSocket.BeginSendTo(datagram, 0, bytes, SocketFlags.None, endPoint, requestCallback, state);
244 }
245
247 {
249 if (!_active)
250 {
252 }
254 }
255
256 private void ValidateDatagram(byte[] datagram, int bytes, IPEndPoint endPoint)
257 {
259 if (datagram == null)
260 {
261 throw new ArgumentNullException("datagram");
262 }
263 if (bytes > datagram.Length || bytes < 0)
264 {
265 throw new ArgumentOutOfRangeException("bytes");
266 }
267 if (_active && endPoint != null)
268 {
270 }
271 }
272
273 private IPEndPoint GetEndpoint(string hostname, int port)
274 {
275 if (_active && (hostname != null || port != 0))
276 {
278 }
279 IPEndPoint result = null;
280 if (hostname != null && port != 0)
281 {
282 IPAddress[] hostAddresses = Dns.GetHostAddresses(hostname);
283 int i;
284 for (i = 0; i < hostAddresses.Length && !IsAddressFamilyCompatible(hostAddresses[i].AddressFamily); i++)
285 {
286 }
287 if (hostAddresses.Length == 0 || i == hostAddresses.Length)
288 {
289 throw new ArgumentException(System.SR.net_invalidAddressList, "hostname");
290 }
291 CheckForBroadcast(hostAddresses[i]);
292 result = new IPEndPoint(hostAddresses[i], port);
293 }
294 return result;
295 }
296
297 public IAsyncResult BeginReceive(AsyncCallback? requestCallback, object? state)
298 {
301 return _clientSocket.BeginReceiveFrom(_buffer, 0, 65536, SocketFlags.None, ref remoteEP, requestCallback, state);
302 }
303
304 public byte[] EndReceive(IAsyncResult asyncResult, ref IPEndPoint? remoteEP)
305 {
308 int num = _clientSocket.EndReceiveFrom(asyncResult, ref endPoint);
309 remoteEP = (IPEndPoint)endPoint;
310 if (num < 65536)
311 {
312 byte[] array = new byte[num];
313 Buffer.BlockCopy(_buffer, 0, array, 0, num);
314 return array;
315 }
316 return _buffer;
317 }
318
319 public void JoinMulticastGroup(IPAddress multicastAddr)
320 {
322 if (multicastAddr == null)
323 {
324 throw new ArgumentNullException("multicastAddr");
325 }
326 if (multicastAddr.AddressFamily != _family)
327 {
329 }
330 if (_family == AddressFamily.InterNetwork)
331 {
332 MulticastOption optionValue = new MulticastOption(multicastAddr);
333 _clientSocket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, optionValue);
334 }
335 else
336 {
337 IPv6MulticastOption optionValue2 = new IPv6MulticastOption(multicastAddr);
338 _clientSocket.SetSocketOption(SocketOptionLevel.IPv6, SocketOptionName.AddMembership, optionValue2);
339 }
340 }
341
342 public void JoinMulticastGroup(IPAddress multicastAddr, IPAddress localAddress)
343 {
345 if (_family != AddressFamily.InterNetwork)
346 {
347 throw new SocketException(10045);
348 }
349 MulticastOption optionValue = new MulticastOption(multicastAddr, localAddress);
350 _clientSocket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, optionValue);
351 }
352
353 public void JoinMulticastGroup(int ifindex, IPAddress multicastAddr)
354 {
356 if (multicastAddr == null)
357 {
358 throw new ArgumentNullException("multicastAddr");
359 }
360 if (ifindex < 0)
361 {
363 }
364 if (_family != AddressFamily.InterNetworkV6)
365 {
366 throw new SocketException(10045);
367 }
368 IPv6MulticastOption optionValue = new IPv6MulticastOption(multicastAddr, ifindex);
369 _clientSocket.SetSocketOption(SocketOptionLevel.IPv6, SocketOptionName.AddMembership, optionValue);
370 }
371
372 public void JoinMulticastGroup(IPAddress multicastAddr, int timeToLive)
373 {
375 if (multicastAddr == null)
376 {
377 throw new ArgumentNullException("multicastAddr");
378 }
379 if (!RangeValidationHelpers.ValidateRange(timeToLive, 0, 255))
380 {
381 throw new ArgumentOutOfRangeException("timeToLive");
382 }
383 JoinMulticastGroup(multicastAddr);
384 _clientSocket.SetSocketOption((_family != AddressFamily.InterNetwork) ? SocketOptionLevel.IPv6 : SocketOptionLevel.IP, SocketOptionName.MulticastTimeToLive, timeToLive);
385 }
386
387 public void DropMulticastGroup(IPAddress multicastAddr)
388 {
390 if (multicastAddr == null)
391 {
392 throw new ArgumentNullException("multicastAddr");
393 }
394 if (multicastAddr.AddressFamily != _family)
395 {
397 }
398 if (_family == AddressFamily.InterNetwork)
399 {
400 MulticastOption optionValue = new MulticastOption(multicastAddr);
401 _clientSocket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.DropMembership, optionValue);
402 }
403 else
404 {
405 IPv6MulticastOption optionValue2 = new IPv6MulticastOption(multicastAddr);
406 _clientSocket.SetSocketOption(SocketOptionLevel.IPv6, SocketOptionName.DropMembership, optionValue2);
407 }
408 }
409
410 public void DropMulticastGroup(IPAddress multicastAddr, int ifindex)
411 {
413 if (multicastAddr == null)
414 {
415 throw new ArgumentNullException("multicastAddr");
416 }
417 if (ifindex < 0)
418 {
420 }
421 if (_family != AddressFamily.InterNetworkV6)
422 {
423 throw new SocketException(10045);
424 }
425 IPv6MulticastOption optionValue = new IPv6MulticastOption(multicastAddr, ifindex);
426 _clientSocket.SetSocketOption(SocketOptionLevel.IPv6, SocketOptionName.DropMembership, optionValue);
427 }
428
429 public Task<int> SendAsync(byte[] datagram, int bytes)
430 {
431 return SendAsync(datagram, bytes, null);
432 }
433
438
439 public Task<int> SendAsync(byte[] datagram, int bytes, string? hostname, int port)
440 {
441 return SendAsync(datagram, bytes, GetEndpoint(hostname, port));
442 }
443
445 {
446 return SendAsync(datagram, GetEndpoint(hostname, port), cancellationToken);
447 }
448
449 public Task<int> SendAsync(byte[] datagram, int bytes, IPEndPoint? endPoint)
450 {
451 ValidateDatagram(datagram, bytes, endPoint);
452 if (endPoint == null)
453 {
454 return _clientSocket.SendAsync(new ArraySegment<byte>(datagram, 0, bytes), SocketFlags.None);
455 }
456 CheckForBroadcast(endPoint.Address);
457 return _clientSocket.SendToAsync(new ArraySegment<byte>(datagram, 0, bytes), SocketFlags.None, endPoint);
458 }
459
461 {
463 if (endPoint == null)
464 {
466 }
467 if (_active)
468 {
470 }
471 CheckForBroadcast(endPoint.Address);
472 return _clientSocket.SendToAsync(datagram, SocketFlags.None, endPoint, cancellationToken);
473 }
474
476 {
480 {
481 SocketReceiveFromResult socketReceiveFromResult = await task.ConfigureAwait(continueOnCapturedContext: false);
482 byte[] buffer = ((socketReceiveFromResult.ReceivedBytes < 65536) ? _buffer.AsSpan(0, socketReceiveFromResult.ReceivedBytes).ToArray() : _buffer);
483 return new UdpReceiveResult(buffer, (IPEndPoint)socketReceiveFromResult.RemoteEndPoint);
484 }
485 }
486
488 {
492 {
493 SocketReceiveFromResult socketReceiveFromResult = await task.ConfigureAwait(continueOnCapturedContext: false);
494 byte[] buffer = ((socketReceiveFromResult.ReceivedBytes < 65536) ? _buffer.AsSpan(0, socketReceiveFromResult.ReceivedBytes).ToArray() : _buffer);
495 return new UdpReceiveResult(buffer, (IPEndPoint)socketReceiveFromResult.RemoteEndPoint);
496 }
497 }
498
499 private void CreateClientSocket()
500 {
502 }
503
504 public UdpClient(string hostname, int port)
505 {
506 if (hostname == null)
507 {
508 throw new ArgumentNullException("hostname");
509 }
511 {
512 throw new ArgumentOutOfRangeException("port");
513 }
514 Connect(hostname, port);
515 }
516
517 public void Close()
518 {
519 Dispose(disposing: true);
520 }
521
522 public void Connect(string hostname, int port)
523 {
525 if (hostname == null)
526 {
527 throw new ArgumentNullException("hostname");
528 }
530 {
531 throw new ArgumentOutOfRangeException("port");
532 }
533 IPAddress[] hostAddresses = Dns.GetHostAddresses(hostname);
534 Exception ex = null;
535 Socket socket = null;
536 Socket socket2 = null;
537 try
538 {
539 if (_clientSocket == null)
540 {
542 {
543 socket2 = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
544 }
546 {
547 socket = new Socket(AddressFamily.InterNetworkV6, SocketType.Dgram, ProtocolType.Udp);
548 }
549 }
550 IPAddress[] array = hostAddresses;
551 foreach (IPAddress iPAddress in array)
552 {
553 try
554 {
555 if (_clientSocket == null)
556 {
557 if (iPAddress.AddressFamily == AddressFamily.InterNetwork && socket2 != null)
558 {
559 socket2.Connect(iPAddress, port);
560 _clientSocket = socket2;
561 socket?.Close();
562 }
563 else if (socket != null)
564 {
565 socket.Connect(iPAddress, port);
566 _clientSocket = socket;
567 socket2?.Close();
568 }
569 _family = iPAddress.AddressFamily;
570 _active = true;
571 break;
572 }
574 {
575 Connect(new IPEndPoint(iPAddress, port));
576 _active = true;
577 break;
578 }
579 }
580 catch (Exception ex2)
581 {
582 if (ExceptionCheck.IsFatal(ex2))
583 {
584 throw;
585 }
586 ex = ex2;
587 }
588 }
589 }
590 catch (Exception ex3)
591 {
592 if (ExceptionCheck.IsFatal(ex3))
593 {
594 throw;
595 }
596 ex = ex3;
597 }
598 finally
599 {
600 if (!_active)
601 {
602 socket?.Close();
603 socket2?.Close();
604 if (ex != null)
605 {
606 throw ex;
607 }
608 throw new SocketException(10057);
609 }
610 }
611 }
612
613 public void Connect(IPAddress addr, int port)
614 {
616 if (addr == null)
617 {
618 throw new ArgumentNullException("addr");
619 }
621 {
622 throw new ArgumentOutOfRangeException("port");
623 }
624 IPEndPoint endPoint = new IPEndPoint(addr, port);
625 Connect(endPoint);
626 }
627
628 public void Connect(IPEndPoint endPoint)
629 {
631 if (endPoint == null)
632 {
633 throw new ArgumentNullException("endPoint");
634 }
635 CheckForBroadcast(endPoint.Address);
636 Client.Connect(endPoint);
637 _active = true;
638 }
639
640 public byte[] Receive([NotNull] ref IPEndPoint? remoteEP)
641 {
643 EndPoint remoteEP2 = ((_family != AddressFamily.InterNetwork) ? IPEndPointStatics.IPv6Any : IPEndPointStatics.Any);
644 int num = Client.ReceiveFrom(_buffer, 65536, SocketFlags.None, ref remoteEP2);
645 remoteEP = (IPEndPoint)remoteEP2;
646 if (num < 65536)
647 {
648 byte[] array = new byte[num];
649 Buffer.BlockCopy(_buffer, 0, array, 0, num);
650 return array;
651 }
652 return _buffer;
653 }
654
655 public int Send(byte[] dgram, int bytes, IPEndPoint? endPoint)
656 {
658 if (dgram == null)
659 {
660 throw new ArgumentNullException("dgram");
661 }
662 if (_active && endPoint != null)
663 {
665 }
666 if (endPoint == null)
667 {
668 return Client.Send(dgram, 0, bytes, SocketFlags.None);
669 }
670 CheckForBroadcast(endPoint.Address);
671 return Client.SendTo(dgram, 0, bytes, SocketFlags.None, endPoint);
672 }
673
674 public int Send(ReadOnlySpan<byte> datagram, IPEndPoint? endPoint)
675 {
677 if (_active && endPoint != null)
678 {
680 }
681 if (endPoint == null)
682 {
683 return Client.Send(datagram, SocketFlags.None);
684 }
685 CheckForBroadcast(endPoint.Address);
686 return Client.SendTo(datagram, SocketFlags.None, endPoint);
687 }
688
689 public int Send(byte[] dgram, int bytes, string? hostname, int port)
690 {
691 return Send(dgram, bytes, GetEndpoint(hostname, port));
692 }
693
694 public int Send(ReadOnlySpan<byte> datagram, string? hostname, int port)
695 {
696 return Send(datagram, GetEndpoint(hostname, port));
697 }
698
699 public int Send(byte[] dgram, int bytes)
700 {
702 if (dgram == null)
703 {
704 throw new ArgumentNullException("dgram");
705 }
706 if (!_active)
707 {
709 }
710 return Client.Send(dgram, 0, bytes, SocketFlags.None);
711 }
712
713 public int Send(ReadOnlySpan<byte> datagram)
714 {
716 if (!_active)
717 {
719 }
720 return Client.Send(datagram, SocketFlags.None);
721 }
722
723 private void ThrowIfDisposed()
724 {
725 if (_disposed)
726 {
727 ThrowObjectDisposedException();
728 }
729 void ThrowObjectDisposedException()
730 {
731 throw new ObjectDisposedException(GetType().FullName);
732 }
733 }
734}
static void BlockCopy(Array src, int srcOffset, Array dst, int dstOffset, int count)
Definition Buffer.cs:102
static void SuppressFinalize(object obj)
Definition GC.cs:202
Definition GC.cs:8
static IPAddress[] GetHostAddresses(string hostNameOrAddress)
Definition Dns.cs:170
static bool IsFatal(Exception exception)
static readonly IPAddress Broadcast
Definition IPAddress.cs:23
override bool Equals([NotNullWhen(true)] object? comparand)
Definition IPAddress.cs:468
static readonly IPAddress Any
Definition IPAddress.cs:19
static readonly IPAddress IPv6Any
Definition IPAddress.cs:27
AddressFamily AddressFamily
Definition IPAddress.cs:88
static readonly IPEndPoint Any
static readonly IPEndPoint IPv6Any
override AddressFamily AddressFamily
Definition IPEndPoint.cs:17
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
Definition Socket.cs:591
int EndSendTo(IAsyncResult asyncResult)
Definition Socket.cs:2525
bool ReceiveFromAsync(SocketAsyncEventArgs e)
Definition Socket.cs:3027
int EndReceiveFrom(IAsyncResult asyncResult, ref EndPoint endPoint)
Definition Socket.cs:2666
IAsyncResult BeginReceiveFrom(byte[] buffer, int offset, int size, SocketFlags socketFlags, ref EndPoint remoteEP, AsyncCallback? callback, object? state)
Definition Socket.cs:2649
virtual void Dispose(bool disposing)
Definition Socket.cs:3294
static bool OSSupportsIPv4
Definition Socket.cs:589
bool SendAsync(SocketAsyncEventArgs e)
Definition Socket.cs:3104
int EndSend(IAsyncResult asyncResult)
Definition Socket.cs:2473
void Bind(EndPoint localEP)
Definition Socket.cs:1172
void Connect(EndPoint remoteEP)
Definition Socket.cs:1206
void SetIPProtectionLevel(IPProtectionLevel level)
Definition Socket.cs:2318
void InternalShutdown(SocketShutdown how)
Definition Socket.cs:3435
bool SendToAsync(SocketAsyncEventArgs e)
Definition Socket.cs:3164
IAsyncResult BeginSendTo(byte[] buffer, int offset, int size, SocketFlags socketFlags, EndPoint remoteEP, AsyncCallback? callback, object? state)
Definition Socket.cs:2513
IAsyncResult BeginSend(byte[] buffer, int offset, int size, SocketFlags socketFlags, AsyncCallback? callback, object? state)
Definition Socket.cs:2433
void SetSocketOption(SocketOptionLevel optionLevel, SocketOptionName optionName, int optionValue)
Definition Socket.cs:2143
UdpClient(string hostname, int port)
Definition UdpClient.cs:504
void CheckForBroadcast(IPAddress ipAddress)
Definition UdpClient.cs:207
int Send(byte[] dgram, int bytes, string? hostname, int port)
Definition UdpClient.cs:689
IAsyncResult BeginSend(byte[] datagram, int bytes, string? hostname, int port, AsyncCallback? requestCallback, object? state)
Definition UdpClient.cs:230
bool IsAddressFamilyCompatible(AddressFamily family)
Definition UdpClient.cs:161
UdpClient(IPEndPoint localEP)
Definition UdpClient.cs:144
Task< int > SendAsync(byte[] datagram, int bytes, string? hostname, int port)
Definition UdpClient.cs:439
ValueTask< int > SendAsync(ReadOnlyMemory< byte > datagram, IPEndPoint? endPoint, CancellationToken cancellationToken=default(CancellationToken))
Definition UdpClient.cs:460
void Connect(IPAddress addr, int port)
Definition UdpClient.cs:613
Task< int > SendAsync(byte[] datagram, int bytes)
Definition UdpClient.cs:429
IAsyncResult BeginSend(byte[] datagram, int bytes, IPEndPoint? endPoint, AsyncCallback? requestCallback, object? state)
Definition UdpClient.cs:235
int EndSend(IAsyncResult asyncResult)
Definition UdpClient.cs:246
ValueTask< int > SendAsync(ReadOnlyMemory< byte > datagram, CancellationToken cancellationToken=default(CancellationToken))
Definition UdpClient.cs:434
int Send(ReadOnlySpan< byte > datagram, IPEndPoint? endPoint)
Definition UdpClient.cs:674
IPEndPoint GetEndpoint(string hostname, int port)
Definition UdpClient.cs:273
byte[] EndReceive(IAsyncResult asyncResult, ref IPEndPoint? remoteEP)
Definition UdpClient.cs:304
int Send(byte[] dgram, int bytes, IPEndPoint? endPoint)
Definition UdpClient.cs:655
readonly byte[] _buffer
Definition UdpClient.cs:14
void DropMulticastGroup(IPAddress multicastAddr, int ifindex)
Definition UdpClient.cs:410
void Connect(string hostname, int port)
Definition UdpClient.cs:522
int Send(byte[] dgram, int bytes)
Definition UdpClient.cs:699
UdpClient(int port, AddressFamily family)
Definition UdpClient.cs:128
bool IsBroadcast(IPAddress address)
Definition UdpClient.cs:216
void JoinMulticastGroup(IPAddress multicastAddr, IPAddress localAddress)
Definition UdpClient.cs:342
Task< UdpReceiveResult > ReceiveAsync()
Definition UdpClient.cs:475
Task< int > SendAsync(byte[] datagram, int bytes, IPEndPoint? endPoint)
Definition UdpClient.cs:449
ValueTask< int > SendAsync(ReadOnlyMemory< byte > datagram, string? hostname, int port, CancellationToken cancellationToken=default(CancellationToken))
Definition UdpClient.cs:444
int Send(ReadOnlySpan< byte > datagram)
Definition UdpClient.cs:713
void AllowNatTraversal(bool allowed)
Definition UdpClient.cs:156
void DropMulticastGroup(IPAddress multicastAddr)
Definition UdpClient.cs:387
void JoinMulticastGroup(IPAddress multicastAddr)
Definition UdpClient.cs:319
IAsyncResult BeginSend(byte[] datagram, int bytes, AsyncCallback? requestCallback, object? state)
Definition UdpClient.cs:225
UdpClient(AddressFamily family)
Definition UdpClient.cs:113
ValueTask< UdpReceiveResult > ReceiveAsync(CancellationToken cancellationToken)
Definition UdpClient.cs:487
void ValidateDatagram(byte[] datagram, int bytes, IPEndPoint endPoint)
Definition UdpClient.cs:256
void Connect(IPEndPoint endPoint)
Definition UdpClient.cs:628
void JoinMulticastGroup(int ifindex, IPAddress multicastAddr)
Definition UdpClient.cs:353
int Send(ReadOnlySpan< byte > datagram, string? hostname, int port)
Definition UdpClient.cs:694
IAsyncResult BeginReceive(AsyncCallback? requestCallback, object? state)
Definition UdpClient.cs:297
void JoinMulticastGroup(IPAddress multicastAddr, int timeToLive)
Definition UdpClient.cs:372
byte[] Receive([NotNull] ref IPEndPoint? remoteEP)
Definition UdpClient.cs:640
virtual void Dispose(bool disposing)
Definition UdpClient.cs:183
static bool ValidatePortNumber(int port)
static string net_protocol_invalid_family
Definition SR.cs:44
static string net_invalidAddressList
Definition SR.cs:42
static string net_udpconnected
Definition SR.cs:30
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string net_protocol_invalid_multicast_family
Definition SR.cs:46
static string net_value_cannot_be_negative
Definition SR.cs:96
static string net_notconnected
Definition SR.cs:24
Definition SR.cs:7