Please see my comment to the question — this is the main part of what you need to do. Sorry, I don't want to spend time on investigation before you do you part of work, but I can only share what's wrong in this code, what I can see from the first glance.
The biggest problem I can see is your try-catch block, with the catch for
. You are doing something which should be done very rarely, as an exclusion, and only if you know exactly what's going on in some particular catch block: you block the propagation of the exception
. Don't do it; this is a misuse of exceptions. Exceptions should not be caught in every place then can appear; the main rule is: let go
. The mechanism is designed to isolate exception handling from "regular" code. I told you what to do in my comment to the question above. In your case, just remove try-catch completely. What you have now simply makes the exception silent, so that's why you don't know what exactly happened.
Now, "filter out problematic characters" is at least weird. Please review it.
More generally, your problem is using "magical constants
", worse, immediate constants
. Why, on Earth, 3, 251 or 255, "M", "QU", "SA"?! Look at your "100". It it repeated twice. If you decide to change it, you will easily forget another place and screw up things heavily. Better, as a minimum, declare all constants explicitly, with the keyword
, this way you won't repeat them and will be able to parametrize the code with them when you find it necessary.
Also, these CodeProject articles could be useful for you, please see:
Quick tool : A minimalistic Telnet library
Windows Mobile Telnet Client