Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ Connect() [3/3]

void System.Net.Sockets.UdpClient.Connect ( string hostname,
int port )
inline

Definition at line 522 of file UdpClient.cs.

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 {
541 if (Socket.OSSupportsIPv4)
542 {
543 socket2 = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
544 }
545 if (Socket.OSSupportsIPv6)
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 }
573 if (IsAddressFamilyCompatible(iPAddress.AddressFamily))
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 }
bool IsAddressFamilyCompatible(AddressFamily family)
Definition UdpClient.cs:161
static bool ValidatePortNumber(int port)

References System.Net.Sockets.UdpClient._active, System.Net.Sockets.UdpClient._clientSocket, System.Net.Sockets.UdpClient._family, System.Net.IPAddress.AddressFamily, System.array, System.Net.Sockets.Socket.Close(), System.Net.Sockets.Socket.Connect(), System.Net.Sockets.Connect, System.Net.Dns.GetHostAddresses(), System.Net.Sockets.UdpClient.IsAddressFamilyCompatible(), System.Net.ExceptionCheck.IsFatal(), System.Net.Sockets.Socket.OSSupportsIPv4, System.Net.Sockets.Socket.OSSupportsIPv6, System.Net.Sockets.Socket, System.Net.Sockets.UdpClient.ThrowIfDisposed(), and System.Net.TcpValidationHelpers.ValidatePortNumber().