Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9079773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:54:55+00:00 2026-06-16T19:54:55+00:00

I am trying to connect to a terminal emulator using a library in android,

  • 0

I am trying to connect to a terminal emulator using a library in android, this will connect to a serial device and should show me sent/received data. I should be able to send data over the connection via a text box below the terminal or by typing in the terminal itself and hitting enter on the keyboard in both cases. There is a function in the library called ‘write’ to write to the emulator screen. However sometimes this works and some times it doesn’t.

In the lines marked [1], [2] and [3] in my code it works fine, for [4] and [5] it does not. Can anybody see why? I create the terminal session before 4 and 5, so it should work for them, it is not. Yet when I start calling write for 1,2,3 it works fine?!

public class TermActivity extends Activity
{
private EditText mEntry;
private EmulatorView mEmulatorView;
private TermSession mSession;
private InputStream bis;
private OutputStream bos;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.term_activity);

    /* Text entry box at the bottom of the activity.  Note that you can
       also send input (whether from a hardware device or soft keyboard)
       directly to the EmulatorView. */
    mEntry = (EditText) findViewById(R.id.term_entry);
    mEntry.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        public boolean onEditorAction(TextView v, int action, KeyEvent ev) {
            // Ignore enter-key-up events
            if (ev != null && ev.getAction() == KeyEvent.ACTION_UP) {
                return false;
            }
            // Don't try to send something if we're not connected yet
            TermSession session = mSession;
            if (mSession == null) {
                return true;
            }

            Editable e = (Editable) v.getText();
            // Write to the terminal session
            //for when i press enter on keyboard.
            [1] session.write(e.toString());
            [2] session.write("test");
            [3] session.write('\r');
            TextKeyListener.clear(e);
            return true;
        }
    });



    /**
     * EmulatorView setup.
     */
    EmulatorView view = (EmulatorView) findViewById(R.id.emulatorView);
    mEmulatorView = view;

    /* Let the EmulatorView know the screen's density. */
    DisplayMetrics metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);
    view.setDensity(metrics);

    /* Create a TermSession. */
    Intent myIntent = getIntent();
    String sessionType = myIntent.getStringExtra("type");
    TermSession session;

    if (sessionType != null && sessionType.equals("telnet")) {
        /* Telnet connection: we need to do the network connect on a
           separate thread, so kick that off and wait for it to finish. */
      //  connectToTelnet(myIntent.getStringExtra("host"));

         byte[] a = new byte[]{'y','y', 'y', 'y', 'y'};
         byte[] b = new byte[]{'a','a', 'l', 'l', 'o'};
        bis = new ByteArrayInputStream(b);
        bos = new ByteArrayOutputStream();


         session = new TelnetSession(bis, bos);


         mEmulatorView.attachSession(session);
         [4]session.write("test");
         mSession = session;
         [5]session.write("test");


        return;
    } else {
        // Create a local shell session.
        session = createLocalTermSession();
        mSession = session;
    }

    /* Attach the TermSession to the EmulatorView. */
    view.attachSession(session);

    /* That's all you have to do!  The EmulatorView will call the attached
       TermSession's initializeEmulator() automatically, once it can
       calculate the appropriate screen size for the terminal emulator. */
}

Socket mSocket;
private static final int MSG_CONNECTED = 1;

/* Create the TermSession which will handle the Telnet protocol and
   terminal emulation. */
private void createTelnetSession() {
    Socket socket = mSocket;

    // Get the socket's input and output streams
    InputStream termIn;
    OutputStream termOut;
    try {
       termIn = socket.getInputStream();
       termOut = socket.getOutputStream();
    } catch (IOException e) {
        //Handle exception here
        return;
    }

    /* Create the TermSession and attach it to the view.  See the
       TelnetSession class for details. */
    byte[] a = new byte[]{'y','y', 'y', 'y', 'y'};
    byte[] b = new byte[]{'a','a', 'l', 'l', 'o'};
    bis = new ByteArrayInputStream(b);
    bos = new ByteArrayOutputStream();


TermSession session = new TelnetSession(bis, bos);  
    mEmulatorView.attachSession(session);
    mSession = session;
    session.write("test");
    try {
        bos.write(a);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T19:54:56+00:00Added an answer on June 16, 2026 at 7:54 pm

    The terminal emulator takes a few seconds to initialise connection and start. Before this, strings written to the emulator are silently dropped.

    So, you can:

    • ignore this if writing to the emulator immediately is not required
    • wait for a fixed period of time
    • check the terminal emulator api to see if there is an api to interrogate the connection status
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to connect to a terminal emulator using a library in android,
I am trying to connect to a terminal emulator using a library in android,
Updated question: I am trying to connect to a terminal emulator using a library
I am connecting to a terminal emulator using a library in android, this connects
Iam trying to connect my android device with a bluetooth compatible device. I know
I am trying to run Hierarchy Viewer. developer.android.com says to Connect your device or
I am trying to connect to a MySQL Server using JDBC tool in java
I am trying to connect the JSF to database. This are the files web.xml
I'm trying to connect to a FTP using Apaches FTPSClient but I keep getting
I'm trying to connect java to a Oracle database within terminal. I'm not very

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.