How to remove data from telnet stream in Winforms Control

0 votes
asked Apr 15, 2016 by jkemp (120 points)

We are currently evaluating the Terminal WinForms Control and so far it has met our needs. However there is one feature I don't see that is a deal-breaker.

My particular situation requires that I be able to sanitize the data coming from the server before it renders. For instance, the server may send ©ABC®. I need to be able to strip the two delimiters and everything between them before they render to the terminal.

I see the DataReceived event but it's after the fact. I also didn't know if I could use the Terminal Emulator in conjunction with the WinForms control to do something like this but I assume the WinForms control is using behind the scene anyway. I haven't really seen anything else in the API.

Any help is greatly appreciated. This is our last hurdle using this product. We can move forward if we can get it working.


commented Apr 18, 2016 by Pavel Matyska (15,060 points)
Hello, I am working on the sample code that should help you with stripping incoming data before they are rendered. Please be patient to tomorrow since it is not as simple as it sounds. "What if the starting delimiter is received in a packet and the ending is (probably) received in the next packet and after some time period due to some network lag" is one example for all, what can make an issue.
commented Apr 18, 2016 by jkemp (120 points)
Thank you so much. I look forward to your example.  I understand what you're saying about the packet separation. I've had to deal with those kinds of coding issues as well so I can appreciate the difficulty.

Just to provide more clarity into what's going on, the case I mentioned above is when our system indicates something should be printed to paper but not the screen.

Item 1 ©Item 1 10®

"Item 1" should print to screen but we redirect "Item 1 10" to the printer.

Thanks again. Just out of curiosity, can you briefly tell me which part of the API (classes or events) you're utilizing to make this happen? If you don't have time I'll just wait until tomorrow.  :)

commented Apr 19, 2016 by Pavel Matyska (15,060 points)
I am enhancing Telnet class implementation of  IShellChannelFactory.CreateShellChannel method, which will be called in Terminal.Bind(IShellChannelFactory) and it will return a wrapper around a ShellChannel which will do the stripping. With your additional information, you'll need not to strip the data, but to fork them. I'll complete the stripping sample, which I believe show you the way to go :)

1 Answer

0 votes
answered Apr 19, 2016 by Pavel Matyska (15,060 points)

Hello, here is a sample code that should help you with stripping data.

Since the code is too long to post it here, you can download a .cs file with the code on our page:

Please modify it to actually 'fork' the data to the printer and to the screen as you would need. Also, this code do not solve the case if the delimiters are multi-byte characters. It only shows how to parse incoming data before they are processed and rendered to the terminal screen.
The use of these classes is simple as using base Telnet class. I used other characters as delimiters, but the point is the same.

StrippingTelnet client = new StrippingTelnet(server);
client.StartingStripDelimiter = (byte)'#';
client.EndingStripDelimiter = (byte)'*';

// terminal is an TerminalControl or VirtualTerminal instance

Please let me know whether you are able to make it work in your scenario.

commented Apr 19, 2016 by jkemp (120 points)

Thank you so much for your help. Unfortunately the file does not seem to contain any code. When I try to download it the file is empty. Is there any way you can upload it again?

Thank you
commented Apr 19, 2016 by Pavel Matyska (15,060 points)
Hello, I zipped the file and upload it here:

Kind regards
commented Apr 19, 2016 by jkemp (120 points)

Thanks. I've received the file successfully. I'll let you know how it goes.