I think your problem is with the following line
I'm assuming your stop sequence is either ~r~n or ~0, right? Well, the problem with that piece of code is that it's only comparing the end of the buffer to see if it matches the stop sequence. The thing is, the original message may be getting split into multiple packets such that your ~r~n or ~0 are ending up in the middle of the packet - therefore they'll be in the middle of your buffer and the above test will fail and the stop sequence won't be found or replaced.
Why don't you try changing the if to the following
I might very well be wrong, but it's the only thing I can think of at the moment.
If Buffer.Length >= s.Length And Right$(Buffer,s.Length) = s Then
I'm assuming your stop sequence is either ~r~n or ~0, right? Well, the problem with that piece of code is that it's only comparing the end of the buffer to see if it matches the stop sequence. The thing is, the original message may be getting split into multiple packets such that your ~r~n or ~0 are ending up in the middle of the packet - therefore they'll be in the middle of your buffer and the above test will fail and the stop sequence won't be found or replaced.
Why don't you try changing the if to the following
If( Buffer.Find( StopSeq, 0 ) ) Local t:String = Buffer.Replace(s,"") 'Strip out the Stop sequence Return t End If
I might very well be wrong, but it's the only thing I can think of at the moment.