tags:

views:

396

answers:

2

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?

+1  A: 

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.

Moose
A: 

I am facing the same problem. Im trying to find out a way in which my client would know that the stream of data has ended. In my application, just like yours, i am running a loop with beginread and storing all collected data in a memorystream. However, i need to know that the data has completed and then i need to send the memorystream to another class for further processing. How did you get about this problem? I will greatly appreciate your help. Thanks.

Batul