Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.wes.telnet;
- import android.os.AsyncTask;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.EditText;
- public class MainActivity extends AppCompatActivity {
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- }
- private TcpClient mTcpClient;
- public void OnbConnect(View view) {
- EditText port = findViewById(R.id.editPort);
- EditText IP = findViewById(R.id.editIP);
- String ip = IP.getText().toString();
- String strPort = port.getText().toString();
- int port = Integer.valueOf(strPort);
- new ConnectTask().execute();
- }
- public void OnbDisconnect(View view) {
- mTcpClient.stopClient();
- }
- public void OnbSend(View view) {
- EditText txt2snd = findViewById(R.id.editSend);
- EditText tv = findViewById(R.id.textIO);
- String txt = txt2snd.getText().toString();
- mTcpClient.sendMessage(txt + "\r\n");
- txt2snd.setText("");
- tv.append(">" + txt +"\r\n");
- }
- public class ConnectTask extends AsyncTask<String, String, TcpClient> {
- @Override
- protected TcpClient doInBackground(String... message) {
- //we create a TCPClient object and
- mTcpClient = new TcpClient(new TcpClient.OnMessageReceived() {
- @Override
- //here the messageReceived method is implemented
- public void messageReceived(final String message) {
- //this method calls the onProgressUpdate
- //publishProgress(message);
- runOnUiThread(new Runnable() {
- @Override
- public void run() {
- EditText text = findViewById(R.id.textIO);
- text.append(message + "\n");
- }
- }, ip, port);
- }
- });
- mTcpClient.run();
- return null;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement