Socket tcp c# how to clear input buffer?

后端 未结 2 1661
不知归路
不知归路 2021-01-25 07:27

I\'m writing an application for windows phone and I need to communicate with a server and transmit data. The SERVER is written in C++ and I cannot modify it. The CLIENT is what

相关标签:
2条回答
  • 2021-01-25 08:16

    The main question was **how to clear the input buffer? ** or am I wrong?=!

    Nevertheless; since you don't have a fixed buffer denoted as seen from you posted code and receive it via the SocketAsyncEventArgs, you could clear it with:

    Array.Clear(e.Buffer, 0, e.Buffer.Length);
    
    0 讨论(0)
  • 2021-01-25 08:19

    oleksii is right, you should call client.Receive() in a loop. You can choose to start a thread that covers the receive section of your code. Also note that client.Receive() will keep trying to receive from the buffer, and it will get stuck if there is no data available.

    0 讨论(0)
提交回复
热议问题