是否有可能Socket和TcpClient的对象之间的转换? [英] Is it possible to convert between Socket and TcpClient objects?

查看:122
本文介绍了是否有可能Socket和TcpClient的对象之间的转换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是对好奇仅仅是基于另一种C#/。NET的问题不止一个立即的需要 ...

如果你有一个插槽实例,你想要把它包在更高级别的的TcpClient 类,是是可能的,你会怎么做呢?

相反,如果你有的TcpClient 的实例,是有可能得到的潜在插槽

解决方案
  

如果你有一个Socket实例,你   想要把它包在更高级别   TcpClient的类,是可能的,   你会怎么做呢?

  Socket套接字= ...;
TcpClient的客户端=新的TcpClient();
client.Client =插座;
 

  

相反,如果你有一个实例   TcpClient的,是有可能得到   底层的Socket?

获取底层的插座中使用<一个href="http://msdn.microsoft.com/en-us/library/system.net.sockets.tcpclient.client.aspx">TcpClient.Client属性。

Here's another C#/.NET question based merely on curiousity more than an immediate need ...

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?

Conversely if you have an instance of TcpClient, is it possible to get the underlying 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?

Get the underlying Socket using TcpClient.Client property.

这篇关于是否有可能Socket和TcpClient的对象之间的转换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆