using System; namespace System.Net.Sockets { /// Provides client connections for TCP network services. // Token: 0x020001F6 RID: 502 public class TcpClient : IDisposable { /// Initializes a new instance of the class. // Token: 0x060010C0 RID: 4288 RVA: 0x00030A8C File Offset: 0x0002EC8C public TcpClient() { this.Init(AddressFamily.InterNetwork); this.client.Bind(new IPEndPoint(IPAddress.Any, 0)); } /// Initializes a new instance of the class with the specified family. /// The of the IP protocol. /// The parameter is not equal to AddressFamily.InterNetwork -or- The parameter is not equal to AddressFamily.InterNetworkV6 // Token: 0x060010C1 RID: 4289 RVA: 0x00030AB4 File Offset: 0x0002ECB4 public TcpClient(AddressFamily family) { if (family != AddressFamily.InterNetwork && family != AddressFamily.InterNetworkV6) { throw new ArgumentException("Family must be InterNetwork or InterNetworkV6", "family"); } this.Init(family); IPAddress ipaddress = IPAddress.Any; if (family == AddressFamily.InterNetworkV6) { ipaddress = IPAddress.IPv6Any; } this.client.Bind(new IPEndPoint(ipaddress, 0)); } /// Initializes a new instance of the class and binds it to the specified local endpoint. /// The to which you bind the TCP . /// The parameter is null. // Token: 0x060010C2 RID: 4290 RVA: 0x00030B14 File Offset: 0x0002ED14 public TcpClient(IPEndPoint local_end_point) { this.Init(local_end_point.AddressFamily); this.client.Bind(local_end_point); } /// Initializes a new instance of the class and connects to the specified port on the specified host. /// The DNS name of the remote host to which you intend to connect. /// The port number of the remote host to which you intend to connect. /// The parameter is null. /// The parameter is not between and . /// An error occurred when accessing the socket. See the Remarks section for more information. // Token: 0x060010C3 RID: 4291 RVA: 0x00030B40 File Offset: 0x0002ED40 public TcpClient(string hostname, int port) { this.Connect(hostname, port); } /// Releases all resources used by the . // Token: 0x060010C4 RID: 4292 RVA: 0x00030B50 File Offset: 0x0002ED50 void IDisposable.Dispose() { this.Dispose(true); GC.SuppressFinalize(this); } // Token: 0x060010C5 RID: 4293 RVA: 0x00030B60 File Offset: 0x0002ED60 private void Init(AddressFamily family) { this.active = false; if (this.client != null) { this.client.Close(); this.client = null; } this.client = new Socket(family, SocketType.Stream, ProtocolType.Tcp); } /// Gets or set a value that indicates whether a connection has been made. /// true if the connection has been made; otherwise, false. // Token: 0x17000593 RID: 1427 // (get) Token: 0x060010C6 RID: 4294 RVA: 0x00030BA0 File Offset: 0x0002EDA0 // (set) Token: 0x060010C7 RID: 4295 RVA: 0x00030BA8 File Offset: 0x0002EDA8 protected bool Active { get { return this.active; } set { this.active = value; } } /// Gets or sets the underlying . /// The underlying network . // Token: 0x17000594 RID: 1428 // (get) Token: 0x060010C8 RID: 4296 RVA: 0x00030BB4 File Offset: 0x0002EDB4 // (set) Token: 0x060010C9 RID: 4297 RVA: 0x00030BBC File Offset: 0x0002EDBC public Socket Client { get { return this.client; } set { this.client = value; this.stream = null; } } /// Gets the amount of data that has been received from the network and is available to be read. /// The number of bytes of data received from the network and available to be read. /// An error occurred when attempting to access the socket. See the Remarks section for more information. /// The has been closed. /// /// /// /// /// // Token: 0x17000595 RID: 1429 // (get) Token: 0x060010CA RID: 4298 RVA: 0x00030BCC File Offset: 0x0002EDCC public int Available { get { return this.client.Available; } } /// Gets a value indicating whether the underlying for a is connected to a remote host. /// true if the socket was connected to a remote resource as of the most recent operation; otherwise, false. // Token: 0x17000596 RID: 1430 // (get) Token: 0x060010CB RID: 4299 RVA: 0x00030BDC File Offset: 0x0002EDDC public bool Connected { get { return this.client.Connected; } } /// Gets or sets a value that specifies whether the allows only one client to use a port. /// true if the allows only one client to use a specific port; otherwise, false. The default is true for Windows Server 2003 and Windows XP Service Pack 2 and later, and false for all other versions. /// An error occurred when attempting to access the underlying socket. /// The underlying has been closed. /// /// /// /// /// // Token: 0x17000597 RID: 1431 // (get) Token: 0x060010CC RID: 4300 RVA: 0x00030BEC File Offset: 0x0002EDEC // (set) Token: 0x060010CD RID: 4301 RVA: 0x00030BFC File Offset: 0x0002EDFC public bool ExclusiveAddressUse { get { return this.client.ExclusiveAddressUse; } set { this.client.ExclusiveAddressUse = value; } } // Token: 0x060010CE RID: 4302 RVA: 0x00030C0C File Offset: 0x0002EE0C internal void SetTcpClient(Socket s) { this.Client = s; } /// Gets or sets information on the linger state of the associated socket. /// A . By default, lingering is disabled. /// /// /// /// /// // Token: 0x17000598 RID: 1432 // (get) Token: 0x060010CF RID: 4303 RVA: 0x00030C18 File Offset: 0x0002EE18 // (set) Token: 0x060010D0 RID: 4304 RVA: 0x00030C54 File Offset: 0x0002EE54 public LingerOption LingerState { get { if ((this.values & TcpClient.Properties.LingerState) != (TcpClient.Properties)0U) { return this.linger_state; } return (LingerOption)this.client.GetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Linger); } set { if (!this.client.Connected) { this.linger_state = value; this.values |= TcpClient.Properties.LingerState; return; } this.client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Linger, value); } } /// Gets or sets a value that disables a delay when send or receive buffers are not full. /// true if the delay is disabled, otherwise false. The default value is false. /// /// /// /// /// // Token: 0x17000599 RID: 1433 // (get) Token: 0x060010D1 RID: 4305 RVA: 0x00030CA0 File Offset: 0x0002EEA0 // (set) Token: 0x060010D2 RID: 4306 RVA: 0x00030CD4 File Offset: 0x0002EED4 public bool NoDelay { get { if ((this.values & TcpClient.Properties.NoDelay) != (TcpClient.Properties)0U) { return this.no_delay; } return (bool)this.client.GetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.Debug); } set { if (!this.client.Connected) { this.no_delay = value; this.values |= TcpClient.Properties.NoDelay; return; } this.client.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.Debug, (!value) ? 0 : 1); } } /// Gets or sets the size of the receive buffer. /// The size of the receive buffer, in bytes. The default value is 8192 bytes. /// An error occurred when setting the buffer size.-or-In .NET Compact Framework applications, you cannot set this property. For a workaround, see the Platform Note in Remarks. /// /// /// /// /// // Token: 0x1700059A RID: 1434 // (get) Token: 0x060010D3 RID: 4307 RVA: 0x00030D24 File Offset: 0x0002EF24 // (set) Token: 0x060010D4 RID: 4308 RVA: 0x00030D60 File Offset: 0x0002EF60 public int ReceiveBufferSize { get { if ((this.values & TcpClient.Properties.ReceiveBufferSize) != (TcpClient.Properties)0U) { return this.recv_buffer_size; } return (int)this.client.GetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveBuffer); } set { if (!this.client.Connected) { this.recv_buffer_size = value; this.values |= TcpClient.Properties.ReceiveBufferSize; return; } this.client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveBuffer, value); } } /// Gets or sets the amount of time a will wait to receive data once a read operation is initiated. /// The time-out value of the connection in milliseconds. The default value is 0. /// /// /// /// /// // Token: 0x1700059B RID: 1435 // (get) Token: 0x060010D5 RID: 4309 RVA: 0x00030DAC File Offset: 0x0002EFAC // (set) Token: 0x060010D6 RID: 4310 RVA: 0x00030DE8 File Offset: 0x0002EFE8 public int ReceiveTimeout { get { if ((this.values & TcpClient.Properties.ReceiveTimeout) != (TcpClient.Properties)0U) { return this.recv_timeout; } return (int)this.client.GetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout); } set { if (!this.client.Connected) { this.recv_timeout = value; this.values |= TcpClient.Properties.ReceiveTimeout; return; } this.client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, value); } } /// Gets or sets the size of the send buffer. /// The size of the send buffer, in bytes. The default value is 8192 bytes. /// /// /// /// /// // Token: 0x1700059C RID: 1436 // (get) Token: 0x060010D7 RID: 4311 RVA: 0x00030E34 File Offset: 0x0002F034 // (set) Token: 0x060010D8 RID: 4312 RVA: 0x00030E68 File Offset: 0x0002F068 public int SendBufferSize { get { if ((this.values & TcpClient.Properties.SendBufferSize) != (TcpClient.Properties)0U) { return this.send_buffer_size; } return (int)this.client.GetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendBuffer); } set { if (!this.client.Connected) { this.send_buffer_size = value; this.values |= TcpClient.Properties.SendBufferSize; return; } this.client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendBuffer, value); } } /// Gets or sets the amount of time a will wait for a send operation to complete successfully. /// The send time-out value, in milliseconds. The default is 0. /// /// /// /// /// // Token: 0x1700059D RID: 1437 // (get) Token: 0x060010D9 RID: 4313 RVA: 0x00030EA8 File Offset: 0x0002F0A8 // (set) Token: 0x060010DA RID: 4314 RVA: 0x00030EDC File Offset: 0x0002F0DC public int SendTimeout { get { if ((this.values & TcpClient.Properties.SendTimeout) != (TcpClient.Properties)0U) { return this.send_timeout; } return (int)this.client.GetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout); } set { if (!this.client.Connected) { this.send_timeout = value; this.values |= TcpClient.Properties.SendTimeout; return; } this.client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, value); } } /// Disposes this instance and requests that the underlying TCP connection be closed. /// /// /// /// /// // Token: 0x060010DB RID: 4315 RVA: 0x00030F1C File Offset: 0x0002F11C public void Close() { ((IDisposable)this).Dispose(); } /// Connects the client to a remote TCP host using the specified remote network endpoint. /// The to which you intend to connect. /// The parameter is null. /// An error occurred when accessing the socket. See the Remarks section for more information. /// The is closed. /// /// /// /// /// /// /// // Token: 0x060010DC RID: 4316 RVA: 0x00030F24 File Offset: 0x0002F124 public void Connect(IPEndPoint remote_end_point) { try { this.client.Connect(remote_end_point); this.active = true; } finally { this.CheckDisposed(); } } /// Connects the client to a remote TCP host using the specified IP address and port number. /// The of the host to which you intend to connect. /// The port number to which you intend to connect. /// The parameter is null. /// The is not between and . /// An error occurred when accessing the socket. See the Remarks section for more information. /// /// is closed. /// /// /// /// /// /// /// // Token: 0x060010DD RID: 4317 RVA: 0x00030F6C File Offset: 0x0002F16C public void Connect(IPAddress address, int port) { this.Connect(new IPEndPoint(address, port)); } // Token: 0x060010DE RID: 4318 RVA: 0x00030F7C File Offset: 0x0002F17C private void SetOptions() { TcpClient.Properties properties = this.values; this.values = (TcpClient.Properties)0U; if ((properties & TcpClient.Properties.LingerState) != (TcpClient.Properties)0U) { this.LingerState = this.linger_state; } if ((properties & TcpClient.Properties.NoDelay) != (TcpClient.Properties)0U) { this.NoDelay = this.no_delay; } if ((properties & TcpClient.Properties.ReceiveBufferSize) != (TcpClient.Properties)0U) { this.ReceiveBufferSize = this.recv_buffer_size; } if ((properties & TcpClient.Properties.ReceiveTimeout) != (TcpClient.Properties)0U) { this.ReceiveTimeout = this.recv_timeout; } if ((properties & TcpClient.Properties.SendBufferSize) != (TcpClient.Properties)0U) { this.SendBufferSize = this.send_buffer_size; } if ((properties & TcpClient.Properties.SendTimeout) != (TcpClient.Properties)0U) { this.SendTimeout = this.send_timeout; } } /// Connects the client to the specified port on the specified host. /// The DNS name of the remote host to which you intend to connect. /// The port number of the remote host to which you intend to connect. /// The parameter is null. /// The parameter is not between and . /// An error occurred when accessing the socket. See the Remarks section for more information. /// /// is closed. /// /// /// /// /// /// /// // Token: 0x060010DF RID: 4319 RVA: 0x00031014 File Offset: 0x0002F214 public void Connect(string hostname, int port) { IPAddress[] hostAddresses = Dns.GetHostAddresses(hostname); this.Connect(hostAddresses, port); } /// Connects the client to a remote TCP host using the specified IP addresses and port number. /// The array of the host to which you intend to connect. /// The port number to which you intend to connect. /// The parameter is null. /// The port number is not valid. /// An error occurred when attempting to access the socket. See the Remarks section for more information. /// The has been closed. /// A caller higher in the call stack does not have permission for the requested operation. /// This method is valid for sockets that use the flag or the flag. /// /// /// /// /// /// /// // Token: 0x060010E0 RID: 4320 RVA: 0x00031030 File Offset: 0x0002F230 public void Connect(IPAddress[] ipAddresses, int port) { this.CheckDisposed(); if (ipAddresses == null) { throw new ArgumentNullException("ipAddresses"); } for (int i = 0; i < ipAddresses.Length; i++) { try { IPAddress ipaddress = ipAddresses[i]; if (ipaddress.Equals(IPAddress.Any) || ipaddress.Equals(IPAddress.IPv6Any)) { throw new SocketException(10049); } this.Init(ipaddress.AddressFamily); if (ipaddress.AddressFamily == AddressFamily.InterNetwork) { this.client.Bind(new IPEndPoint(IPAddress.Any, 0)); } else { if (ipaddress.AddressFamily != AddressFamily.InterNetworkV6) { throw new NotSupportedException("This method is only valid for sockets in the InterNetwork and InterNetworkV6 families"); } this.client.Bind(new IPEndPoint(IPAddress.IPv6Any, 0)); } this.Connect(new IPEndPoint(ipaddress, port)); if (this.values != (TcpClient.Properties)0U) { this.SetOptions(); } break; } catch (Exception ex) { this.Init(AddressFamily.InterNetwork); if (i == ipAddresses.Length - 1) { throw ex; } } } } /// Asynchronously accepts an incoming connection attempt. /// An object returned by a call to . /// The parameter is null. /// The parameter was not returned by a call to a method. /// The method was previously called for the asynchronous connection. /// An error occurred when attempting to access the . See the Remarks section for more information. /// The underlying has been closed. /// /// /// /// /// // Token: 0x060010E1 RID: 4321 RVA: 0x0003115C File Offset: 0x0002F35C public void EndConnect(IAsyncResult asyncResult) { this.client.EndConnect(asyncResult); } /// Begins an asynchronous request for a remote host connection. The remote host is specified by an and a port number (). /// An object that references the asynchronous connection. /// The of the remote host. /// The port number of the remote host. /// An delegate that references the method to invoke when the operation is complete. /// A user-defined object that contains information about the connect operation. This object is passed to the delegate when the operation is complete. /// The parameter is null. /// An error occurred when attempting to access the socket. See the Remarks section for more information. /// The has been closed. /// A caller higher in the call stack does not have permission for the requested operation. /// The port number is not valid. /// /// /// /// /// /// /// // Token: 0x060010E2 RID: 4322 RVA: 0x0003116C File Offset: 0x0002F36C public IAsyncResult BeginConnect(IPAddress address, int port, AsyncCallback callback, object state) { return this.client.BeginConnect(address, port, callback, state); } /// Begins an asynchronous request for a remote host connection. The remote host is specified by an array and a port number (). /// An object that references the asynchronous connection. /// At least one that designates the remote hosts. /// The port number of the remote hosts. /// An delegate that references the method to invoke when the operation is complete. /// A user-defined object that contains information about the connect operation. This object is passed to the delegate when the operation is complete. /// The parameter is null. /// An error occurred when attempting to access the socket. See the Remarks section for more information. /// The has been closed. /// A caller higher in the call stack does not have permission for the requested operation. /// The port number is not valid. /// /// /// /// /// /// /// // Token: 0x060010E3 RID: 4323 RVA: 0x00031180 File Offset: 0x0002F380 public IAsyncResult BeginConnect(IPAddress[] addresses, int port, AsyncCallback callback, object state) { return this.client.BeginConnect(addresses, port, callback, state); } /// Begins an asynchronous request for a remote host connection. The remote host is specified by a host name () and a port number (). /// An object that references the asynchronous connection. /// The name of the remote host. /// The port number of the remote host. /// An delegate that references the method to invoke when the operation is complete. /// A user-defined object that contains information about the connect operation. This object is passed to the delegate when the operation is complete. /// The parameter is null. /// An error occurred when attempting to access the socket. See the Remarks section for more information. /// The has been closed. /// A caller higher in the call stack does not have permission for the requested operation. /// The port number is not valid. /// /// /// /// /// /// /// // Token: 0x060010E4 RID: 4324 RVA: 0x00031194 File Offset: 0x0002F394 public IAsyncResult BeginConnect(string host, int port, AsyncCallback callback, object state) { return this.client.BeginConnect(host, port, callback, state); } /// Releases the unmanaged resources used by the and optionally releases the managed resources. /// Set to true to release both managed and unmanaged resources; false to release only unmanaged resources. // Token: 0x060010E5 RID: 4325 RVA: 0x000311A8 File Offset: 0x0002F3A8 protected virtual void Dispose(bool disposing) { if (this.disposed) { return; } this.disposed = true; if (disposing) { NetworkStream networkStream = this.stream; this.stream = null; if (networkStream != null) { networkStream.Close(); this.active = false; } else if (this.client != null) { this.client.Close(); this.client = null; } } } /// Frees resources used by the class. // Token: 0x060010E6 RID: 4326 RVA: 0x00031214 File Offset: 0x0002F414 ~TcpClient() { this.Dispose(false); } /// Returns the used to send and receive data. /// The underlying . /// The is not connected to a remote host. /// The has been closed. /// /// /// /// /// // Token: 0x060010E7 RID: 4327 RVA: 0x00031250 File Offset: 0x0002F450 public NetworkStream GetStream() { NetworkStream networkStream; try { if (this.stream == null) { this.stream = new NetworkStream(this.client, true); } networkStream = this.stream; } finally { this.CheckDisposed(); } return networkStream; } // Token: 0x060010E8 RID: 4328 RVA: 0x000312B0 File Offset: 0x0002F4B0 private void CheckDisposed() { if (this.disposed) { throw new ObjectDisposedException(base.GetType().FullName); } } // Token: 0x04000F29 RID: 3881 private NetworkStream stream; // Token: 0x04000F2A RID: 3882 private bool active; // Token: 0x04000F2B RID: 3883 private Socket client; // Token: 0x04000F2C RID: 3884 private bool disposed; // Token: 0x04000F2D RID: 3885 private TcpClient.Properties values; // Token: 0x04000F2E RID: 3886 private int recv_timeout; // Token: 0x04000F2F RID: 3887 private int send_timeout; // Token: 0x04000F30 RID: 3888 private int recv_buffer_size; // Token: 0x04000F31 RID: 3889 private int send_buffer_size; // Token: 0x04000F32 RID: 3890 private LingerOption linger_state; // Token: 0x04000F33 RID: 3891 private bool no_delay; // Token: 0x020001F7 RID: 503 private enum Properties : uint { // Token: 0x04000F35 RID: 3893 LingerState = 1U, // Token: 0x04000F36 RID: 3894 NoDelay, // Token: 0x04000F37 RID: 3895 ReceiveBufferSize = 4U, // Token: 0x04000F38 RID: 3896 ReceiveTimeout = 8U, // Token: 0x04000F39 RID: 3897 SendBufferSize = 16U, // Token: 0x04000F3A RID: 3898 SendTimeout = 32U } } }