SslStream.DataAvailable 不是有效的函数

发布于 2024-07-16 03:27:21 字数 2183 浏览 4 评论 0原文

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

错误 1“System.Net.Security.SslStream” 不包含以下定义 “DataAvailable”且无扩展名 方法“DataAvailable”接受 类型的第一个参数 “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 中的数据是否可用?

I am migrating C# code from using a NetworkStream to SSLStream, however where I use stream.DataAvailable I get the error:

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?)

now my local MSDN copy does not include DataAvailable as a member of SslStream however http://msdn.microsoft.com/en-us/library/dd170317.aspx says it does have the member DataAvailable.
here is a copy of my code.

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);
     ...

Also if you have a better way to get my output of the stream in to a managed array (there will be some parsing done on it later in the code) I would love the help. I am using Visual Studio 2008

--EDIT
I just realized I linked to the embedded SDK, this is not a embedded system, so how do I see if data is available in the normal .net SDK?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

酷炫老祖宗 2024-07-23 03:27:21

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

根据 此 .Net 页面2.0此页面适用于 .Net 3.5 ,SSLStream 上没有 DataAvailable 属性。

编辑:你不能只调用 Read() 看看是否能得到任何结果吗? 我不认为这会阻止。

The page you are looking at is for the .NET Micro Framework.

According to this page for .Net 2.0 and this page for .Net 3.5, there is no DataAvailable property on SSLStream.

Edit: Can't you just call Read() and see if you get anything back? i don't think this will block.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文