Tuy nhiên, lớp TcpClient không cung cấp cho chúng tôi tiếp cận để dụ socket cơ bản của nó thông qua socket bảo vệ tài sản của mình. Kể từ khi tài sản được bảo vệ, nó chỉ có thể được truy cập bằng cách mở rộng các lớp học TcpClient ban đầu. Chúng tôi đã quyết định để minh họa kỹ thuật này bằng cách mở rộng các lớp TcpClient | 140 Chapter 4 Beyond the Basics Figure Transcode Server protocol termination. As we mentioned earlier some advanced functionality is available only in the Socket class and not the higher level socket classes like TcpClient. The Shutdown method of the Socket class is an example of a feature that is not directly accessible in the TcpClient class. However the TcpClient class does give us access to its underlying Socket instance through its protected Socket property. Since the property is protected it can only be accessed by extending the original TcpClient class. We have decided to illustrate this technique here by extending the TcpClient class to access the Socket method Shutdown . We have created the TcpClientShutdown class in order to do this. 0 using System For String 1 using For IPEndPoint EndPoint 2 using For TcpClient SocketShutdown 3 4 class TcpClientShutdown TcpClient 5 6 public TcpClientShutdown base 7 public TcpClientShutdown IPEndPoint localEP base localEP 8 public TcpClientShutdown String server int port base server port 9 10 public void Shutdown SocketShutdown ss 11 Invoke the Shutdown method on the underlying socket 12 ss 13 Closing Connections 141 14 public EndPoint GetRemoteEndPoint 15 Return the RemoteEndPoint from the underlying socket 16 return 17 18 1. Extend the TcpClient class line 4 2. Extend the constructors lines 6-8 Extending the constructors with the base keyword is required. Additional constructor logic can also be added but is not required. 3. Shutdown lines 10-13 The new user-defined Shutdown method invokes the Socket method of the same name by using the Client property. 4. GetRemoteEndPoint lines 14-17 The new user-defined GetRemoteEndPoint method retrieves the RemoteEndPoint property from the underlying Socket by using the Client property. 0 using System For String Int32 Console .