简体   繁体   中英

Reading from networkstream without losing data

I have client-server application. I need way to asynchronously peek what client sends to server and react accordingly. I have access only to network stream therefore if i use NetworkStream.Read() i lose data that was in the stream. I tried to write data back to stream but then i still am not able to access stream on the server side.

Is there any way to peek the NetworkStream? If i'm not mistaken there is way to that by using socket object and invoking Receive method. Problem is that socket property in NetworkStream is protected so i can't use it. Can i access somehow this particular socket ?

Thank you for your help.

No, basically. It does not expose any peek API. You would have to maintain your own buffer. Note: you also can't write back into the read stream - if you write to a NetworkStream you are sending that data to the other machine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM