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

◆ Connect() [4/4]

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

Definition at line 209 of file TcpClient.cs.

210 {
212 if (hostname == null)
213 {
214 throw new ArgumentNullException("hostname");
215 }
217 {
218 throw new ArgumentOutOfRangeException("port");
219 }
220 if (_active)
221 {
222 throw new SocketException(10056);
223 }
224 IPAddress[] hostAddresses = Dns.GetHostAddresses(hostname);
225 ExceptionDispatchInfo exceptionDispatchInfo = null;
226 try
227 {
228 IPAddress[] array = hostAddresses;
229 foreach (IPAddress iPAddress in array)
230 {
231 try
232 {
233 if (_clientSocket == null)
234 {
235 if ((iPAddress.AddressFamily == AddressFamily.InterNetwork && Socket.OSSupportsIPv4) || Socket.OSSupportsIPv6)
236 {
237 Socket socket = new Socket(iPAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
238 if (iPAddress.IsIPv4MappedToIPv6)
239 {
240 socket.DualMode = true;
241 }
243 if (Disposed)
244 {
245 socket.Dispose();
246 }
247 try
248 {
249 socket.Connect(iPAddress, port);
250 }
251 catch
252 {
253 _clientSocket = null;
254 throw;
255 }
256 }
257 _family = iPAddress.AddressFamily;
258 _active = true;
259 break;
260 }
261 if (iPAddress.AddressFamily == _family || _family == AddressFamily.Unknown)
262 {
263 Connect(new IPEndPoint(iPAddress, port));
264 _active = true;
265 break;
266 }
267 }
268 catch (Exception ex) when (!(ex is OutOfMemoryException))
269 {
270 exceptionDispatchInfo = ExceptionDispatchInfo.Capture(ex);
271 }
272 }
273 }
274 finally
275 {
276 if (!_active)
277 {
278 exceptionDispatchInfo?.Throw();
279 throw new SocketException(10057);
280 }
281 }
282 }
AddressFamily AddressFamily
Definition Socket.cs:748
static bool ValidatePortNumber(int port)
static ExceptionDispatchInfo Capture(Exception source)
static int Exchange(ref int location1, int value)

References System.Net.Sockets.TcpClient._active, System.Net.Sockets.TcpClient._clientSocket, System.Net.Sockets.TcpClient._family, System.Net.IPAddress.AddressFamily, System.array, System.Runtime.ExceptionServices.ExceptionDispatchInfo.Capture(), System.Net.Sockets.Socket.Connect(), System.Net.Sockets.Connect, System.Net.Sockets.Socket.Dispose(), System.Net.Sockets.TcpClient.Disposed, System.Threading.Interlocked.Exchange(), System.Net.Dns.GetHostAddresses(), System.Net.IPAddress.IsIPv4MappedToIPv6, System.Net.Sockets.Socket.OSSupportsIPv4, System.Net.Sockets.Socket.OSSupportsIPv6, System.Net.Sockets.Socket, System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw(), System.Net.Sockets.TcpClient.ThrowIfDisposed(), and System.Net.TcpValidationHelpers.ValidatePortNumber().

Referenced by Terraria.Net.Sockets.TcpSocket.Connect(), System.Net.FtpWebRequest.CreateConnection(), and System.Net.Mail.SmtpConnection.InitializeConnection().