c# - 是否可以在 Socket 和 TcpClient 对象之间进行转换?

标签 c# .net sockets tcpclient system.net

这是另一个 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/

相关文章:

c - 通过滑动窗口协议(protocol)进行数据转换,C

c# - 有什么办法可以在 x :DataType? 中使用值类型

c# - 如何在 Application Insights 中通过 RabbitMQ 显示端到端事务?

c# - 无法使用模拟器上传文件, Controller 有问题

c# - NumericUpDown UpdateEditText 在输入值时导致问题

java - 简单的 Web 服务器在收到 http 请求时挂起

c - 使用 UDP 套接字的多个 sendto()

c# - 用 Mono 编译 csharp 项目

c# - 如何在 WinForms 应用程序中存储连接字符串?

.net - 在 .NET 中运行 BAT 程序