c# - SslStream.DataAvailable 不是有效函数

标签 c# .net ssl msdn

我正在将 C# 代码从使用 NetworkStream 迁移到 SSLStream,但是在我使用 stream.DataAvailable 的地方出现错误:

Error 1 'System.Net.Security.SslStream' does not contain a definition for 'DataAvailable' and no extension method 'DataAvailable' accepting a first argument of type 'System.Net.Security.SslStream' could be found (are you missing a using directive or an assembly reference?)

现在我的本地 MSDN 副本不包括作为 SslStream 成员的 DataAvailable http://msdn.microsoft.com/en-us/library/dd170317.aspx说它确实有成员 DataAvailable。 这是我的代码的副本。

using System;
using System.Collections;
using System.Collections.Generic;
using System.Net;
using System.Net.Sockets;
using System.Net.Security;
using System.Security.Authentication;
using System.Security.Cryptography.X509Certificates;
using System.IO;

namespace Node
{

  public static class SSLCommunicator
  {
    static TcpClient client = null;
    static SslStream stream = null;
    static List<byte> networkStreamInput = new List<byte>();
    public static void connect(string server, Int32 port)
    {
        try
        {
          client = new TcpClient(server, port);
          stream = new SslStream(client.GetStream(),false);
    ...
    ...
    ...
    public static List<DataBlock> getServerInput() 
    {
      List<DataBlock> ret = new List<DataBlock>();
      try
      {
      //check to see if stream is readable.
      if (stream.CanRead)
      {
        //Check to see if there is data available.
        if (stream.DataAvailable)
        {
          byte[] readBuffer = new byte[1024];
          int numberOfBytesRead = 0;
          //while data is available buffer the data.
          do
          {
            numberOfBytesRead = stream.Read(readBuffer, 0, readBuffer.Length);
            byte[] tmp = new byte[numberOfBytesRead];
            Array.Copy(readBuffer, tmp, numberOfBytesRead);
            networkStreamInput.AddRange(tmp);
          } while (stream.DataAvailable);
     ...

此外,如果您有更好的方法将我的流输出放入托管数组(代码稍后会对其进行一些解析),我会很乐意提供帮助。我正在使用 Visual Studio 2008

--编辑 我刚刚意识到我链接到嵌入式 SDK,这不是嵌入式系统,那么我如何查看普通 .net SDK 中的数据是否可用?

最佳答案

您正在查看的页面适用于 .NET Micro Framework。

根据 this page for .Net 2.0this page for .Net 3.5 , SSLStream 上没有 DataAvailable 属性。

编辑:您不能只调用 Read() 并查看是否返回任何内容吗?我认为这不会阻塞。

关于c# - SslStream.DataAvailable 不是有效函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/691085/

相关文章:

c# - TFS/VS 错误地将文件标记为有更改?

c# - 从数据库中选择性获取和删除帖子

.net - MonoDevelop调试时读取环境变量

ruby-on-rails - Rails 设置生产环境在本地机器上使用 SSL

amazon-web-services - AWS CodeDeploy 未在 Lightsail 基本设置 SSL 上部署

Asp.net 检测 iis 是否具有域的 https 证书?

c# - 在 Windows 7 和 Vista 中为我的应用程序文件类型添加属性到详细信息 Pane

c# - 向打印机发送转义字符

c# - EF Core 选择有条件的对象

.net - VS 2012 (VB.net) 忽略 Windows 7 64 位上未处理的异常