+1 vote
by (130 points)


We are evaluating the Xamarin.Android component before placing the order. For this we are using the trial version of the Xamarin.Android project.

However, we are not able to find the complete API's directly which we can use to integrate the xamarin.android component.
We are trying to establish the telnet connection and we need help with below calls\ identifying the API's,
1)Which class to use to establish the telnet connection?
2)Connect api
3)Disconnect api
4)Send api
5)Receive api
6)Is xamarin.android is thread safe? Can we make multiple calls on it from different thread?
7)What is the difference between Bind and StartScripting?
8)What is the use of VirtualTerminal and why we should use it in our android project?
9)How to retrieve each character attributes like underline, bold, reverse video, blinking or colored?
10)How to get the response from host and how to send the user input to host?
11)Is there any logging mechanism available in xamarin.android project, if yes then what are the api's which we can use?


2 Answers

0 votes
by (58.9k points)
edited by


1) to establish the telnet connection there is the Telnet class. It is best utilized in combination with our powerful Scripting API.

2) connect to Telnet servers

3) when working with the Scripting API, it features scripting.Close(); method

4) sending data and communicating with Telnet servers is most easily done via the Scripting class. See code sample on Scripting

5) see chapter about reading response from Telnet/SSH servers

6) In the Telnet protocol you cannot send two commands from one Telnet client to the server at the same time, so this does not make sense. If you need to make non-blocking calls to keep your GUI responsive, of course you can call the methods of Telnet/Scripting classes from a dedicated thread. If you need to perform more tasks at once at the server, you need to create a special Telnet connection for each request.

7) Both Bind and StartScripting methods internally create a new connection to Telnet server. StartScripting is a method from the Telnet class that you can call (and then it internally creates its own VirtualTerminal object), whereas the Bind method is typically used to bind an existing terminal control (GUI) or virtual terminal (GUI-less) to a Telnet class.
See more details.

8) As long as you do a Telnet.StartScripting which is recommended, then the Virtual terminal is automatically created for you. The virtual terminal is then accessible as property of Scripting class Scripting.Terminal.

In more details, Virtual terminal is a class deigned for easy communication with Telnet and SSH servers. You can imagine it as GUI-less virtual terminal. In fact we do not yet offer a GUI terminal control for Xamarin.Android, so the virtual terminal is what you need here. From our documentation:

"VirtualTerminal is a terminal emulation object that is very similar to TerminalControl, but there is one major difference - it's not visible. In fact, it's not even a control. Otherwise, it shares most features with TerminalControl and is suitable for applications that need to interact with SSH or telnet servers but don't need to display the actual terminal session." The powerful Scripting API is built on top of Virtual Terminal and it is a good class to use if you need to script a specific task with Rebex Terminal emulation component.

9) to retrieve a character at a screen position, just use the
Terminal.Screen.GetCell method which returns the TerminalCell like this:

int column = 10;
int row = 20;
TerminalCell cell = scripting.Terminal.Screen.GetCell(column, row);

and then read TerminalCell properties:


10) to send data to Telnet server and read server response, use these methods:

scripting.Send("data"); // sends the data to server
scripting.SendCommand("data"); // sends the data and newline and then waits for server response

scripting.WaitFor(ScriptEvent.Prompt); // waits for a ScriptEvent condition to be met
scripting.ReadUntil(ScriptEvent.Prompt); // returns data received until a ScriptEvent condition is met

11) The Telnet class has a built-in LogWriter. Another possibility is session recording. The recorded sessions can be later replayed via our ANSI player sample.

by (58.9k points)
0 votes
by (58.9k points)

Here is a short code that connects to Telnet server and then authenticates and performs a simple command and receives server response (via the Scripting class):

string username = "user";
string password = "password";

Telnet telnet = new Telnet("server");
var scripting = telnet.StartScripting(); // this method connects to Telnet server

/* sequence of commands to login to Telnet server */
scripting.WaitFor(ScriptEvent.FromString("ogin:")); // wait for "login" prompt
scripting.SendCommand(username); // send user name
scripting.WaitFor(ScriptEvent.FromString("assword:")); // wait for "password" prompt
scripting.SendCommand(password); // send password

/* detect prompt */

/* send data, receive server response */
scripting.SendCommand("ls -la"); // send ls -la command
string response = scripting.ReadUntil(ScriptEvent.Prompt); // returns the server response

/* disconnet from Telnet server */ 
by (130 points)
Thank you  very much for detailed overview.