PowerTCP Emulation for .NETfrom $699.00
Windows Forms Automated Telnet Session Example
The following example demonstrates an automated Telnet session in a Windows Forms environment. The session is executed asynchronously, without blocking the UI. The session is written to the VT display.
private void button1_Click(object sender, EventArgs e)
//This application has a User-Interface, which we do not want to block.
//Start launches the specified method on a worker thread.
//Event handlers execute on the UI thread.
private void automateSession(object notUsed)
//This function performs an automated telnet session using blocking calls.
//Use the Start method to execute this function on a worker thread.
//Connect to the server
//Login and marshal data to the UI thread
telnet1.Marshal(telnet1.Login(new Credentials("myUser", "myPass", "~$")), "", null);
//Send a list command
//Wait for prompt, marshal data to the UI thread
telnet1.Marshal(telnet1.ReadToDelimiter("~$"), "", null);
//Send an exit command; server will close the connection
//Read any remaining data before the shutdown
telnet1.Marshal(telnet1.ReadToEnd(), "", null);
catch (Exception ex)
//Report errors to the UI thread
void telnet1_Data(object sender, DataEventArgs e)
//Add data received to the VT display
if (e.Data != null) vt1.Write(e.Data.ToString());
void telnet1_Error(object sender, ErrorEventArgs e)
//Add error messages to the VT display
void telnet1_StateChanged(object sender, EventArgs e)
//Indicate in app title when connected
this.Text = (telnet1.State == Dart.Emulation.ConnectionState.Closed)
? "Automated Session Demo"
: "Automated Session Demo <Connected to " + telnet1.RemoteEndPoint.ToString() + ">";