这是另一个 C#/.NET 问题,只是出于好奇而不是直接需要 ...
如果你有一个 Socket
实例,并且你想将它包装在更高级别的 TcpClient
类中,这可能吗?你会怎么做?
反过来,如果你有一个TcpClient
的实例,是否有可能获得底层的Socket
?
最佳答案
If you had a Socket instance and you wanted to wrap it in the higher-level TcpClient class, is that possible and how would you do it?
Socket socket = ...;
TcpClient client = new TcpClient();
client.Client = socket;
Conversely if you have an instance of TcpClient, is it possible to get the underlying Socket?
使用 TcpClient.Client 获取底层 Socket属性(property)。
关于c# - 是否可以在 Socket 和 TcpClient 对象之间进行转换?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/203147/