c# - Flush the buffer after receiving packets -
this question has answer here:
- socket tcp c# how clear input buffer? 2 answers
i using below code receiving tcp packets tool.
while(socket.connected) { var buffer = new byte[4096]; int receivelength = socket.receive(buffer); if (receivelength != 0) { byte[] response= new byte[4096]; processpacketdata(buffer, out response); socket.send(resposne); } //sleep(100); }
when using code, problem facing is,for socket.receive() function buffer doesn't getting flushed. every time, when calling socket.receive(buffer), new data packets getting appended old packets contained in buffer. want avoid situation. there solution this?
receive
not receive packets. receives amount of bytes greater 0 bytes. use return value receivelength
find out how received , process amount.
Comments
Post a Comment