SslStream.DataAvailable不是有效的函数

时间:2009-03-27 19:05:49

标签: c# .net ssl msdn

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

  

错误1'System.Net.Security.SslStream'   不包含的定义   'DataAvailable'并没有扩展名   方法'DataAvailable'接受a   类型的第一个参数   'System.Net.Security.SslStream'可以   被发现(你错过了使用   指令或程序集引用?)

现在我的本地MSDN副本不包含DataAvailable作为SslStream的成员,但是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中是否有数据?

1 个答案:

答案 0 :(得分:2)

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

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

编辑:你不能只是调用Read()并看看你是否得到了回报?我认为这不会阻止。