Data remains in SslStream after read

327 views Asked by At

I'm developing a peer-to-peer software, that uses .net's SslStream for secure communication.

I use BeginRead() and EndRead() to read the data from the stream asynchronously. (Don't mind the weird callback method too much.. it's from a framework I have to work with right now)

while(Config.State < Config.State.Exit)
{

    association.SslStream.BeginRead(
                InputBuffer,
                InputBufferOffset,
                InputBuffer.Length - InputBufferOffset,
                iarPort.Post,
                null);

    yield return Arbiter.Receive(false, iarPort, iar =>
            {
                try
                {
                    bytesReceived = association.SslStream.EndRead(iar);
                }
                catch
                {
                    bytesReceived = 0;
                }
            });

// process data

}

The client will process the received data and start reading again. If the remote client has not sent new data yet, the receiving client will read the old data again. So the data remains in the SslStream after it was read.

Is there a way to tell the client that he has already read this data?

1

There are 1 answers

1
usr On BEST ANSWER

The data does not remain in the stream after it was read. If it was that would be a severe bug. That is so unlikely that I'd rather look at my own code first.

You are probably misusing the stream in some way. Maybe you are seeing old data in the byte[] buffer because your code does not respect the bytesReceived value. Or there was an error, which you suppressed in the catch clause. Maybe you just did not notice the error.

If I did not guess the bug (had to guess because there is not enough information here to find it) then you should probably use the debugger to step through your problem and find out what's wrong.